locked
PreProcessQuery and Computed Field RRS feed

  • Question

  • Can I use a computed field in PreProcessQuery ? 

    I'm getting unable to load data with red x on screen.

    The code is 

     partial void PatientReminders_PreprocessQuery(ref IQueryable<LettersSentItem> query)
                 {
                     query = from LettersSentItem p in query
                             where p.ResponseTime > 28
                             select p;  
                 }

    Thursday, March 8, 2012 10:21 AM

Answers

  • The solution to your problem is this:

    Using the query designer modify your query to include

    And DateSent < @dateSent

    Add the query at the screen.

    Remove the DateTime picker automatically added for dateSent parameter (if exists).

    then on the screen's InitializeDataworkspace write

    dateSent = DateTime.Now.AddDays(-28);

    You are ready.


    1+1 = 3 for large values of 1


    Thursday, March 8, 2012 11:11 AM

All replies

  • Calculated fields cannot be used as query parameters or filters in any way. There is nothing you are doing wrong or can do to fix it, except for moving your calculation logic to the database and create the calculated field in the database table.

    1+1 = 3 for large values of 1


    Thursday, March 8, 2012 11:01 AM
  • I have created a computed field in database table(ResponseTime) then tried to use it PreProcessQuery but no luck. 
    Thursday, March 8, 2012 11:06 AM
  • The solution to your problem is this:

    Using the query designer modify your query to include

    And DateSent < @dateSent

    Add the query at the screen.

    Remove the DateTime picker automatically added for dateSent parameter (if exists).

    then on the screen's InitializeDataworkspace write

    dateSent = DateTime.Now.AddDays(-28);

    You are ready.


    1+1 = 3 for large values of 1


    Thursday, March 8, 2012 11:11 AM
  • You mean you:

    1. removed calculated ResponseTime from LS
    2. added ResponseTime calculated field in database
    3. checked that the value calculated is correct
    4. updated your datasource to import ResponseTime as a normal read-only field and not calculated
    5. added ResponseTime condition back to the query

    and still your query didn't work?


    1+1 = 3 for large values of 1



    Thursday, March 8, 2012 11:42 AM
  • Kostas,

    Yes I exactly did the same. But some how my query is not working. Thanks for the work around.

    But I have more than 4 queries with similar condition. Ex: No response for 2 weeks , no response for 4 weeks etc.  And in the end I want to make a screen showing all these 4 different queries. In that  case I can't use screen's InitializeDataworkspace . Am I right ?

    So Computed Fields can't be used in PreProcessQuery ? 

    Friday, March 9, 2012 1:31 AM
  • Why not using the same formula you used in the calculated field in your PreProcessQuery ?

    for eg. query = query.Where(Function(c)(c.ResponseDate.AddDays(28) > Now))

    Please show us ResponseTime_Calculate method, and I'll try to help you.


    Like Yann Said : "If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer". This will help people find the answers that they're looking for more quickly."


    Friday, March 9, 2012 1:36 AM
  • I tried to use the same formula in PreProcessQuery but it wasn't working. Anyways here is the computed field code. 

    partial void ResponseTime_Compute(ref int? result)
    {
     result=(int)(DateTime.Today - DateSent.Date).TotalDays;
    }

    Friday, March 9, 2012 2:03 AM
  • Yes Computed Fields cannot be used in preprocessquery. The scenario you describe is fully supported by my workaround. Eitherway you need 4 queries on your screen. So you can add 4 times the same query with 4 different parameters and set all values. Also this makes your implementation more flexible as these parameters can be at a later stage defined by the user and not require changing the server to change the view.

    Anyway you know your requirements better than me, but I suggest what I would do.



    Friday, March 9, 2012 8:06 AM
  • It's easy. Add a parameter to your query PatientsReminder, name it for eg NumDays, of type Integer.

    Click on Write code -> PreprocessQuery

    Write this (VB)

    query = query.Where(Function(c)(c.ResponseDate.AddDays(NumDays) < Now))

    In Your Screen add the query PatientsReminder (or replace your table with the query)

    Drag-Drop your query to your Screen, LS Will automatically create a Grid and Also a Textbox with your NumDate Value

    Now click on the property NumDay in the left part of the screen (the property, not the control)

    Click on Choice List and Add what you want (2 Weeks (value = 14), 4 Weeks (value = 28), etc...)

    Now in Screen_InitializeDataWorkSpace, initialize your property 

    NumDays = 28 (or what ever you like)

    Hope it's clear.




    Like Yann Said : "If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer". This will help people find the answers that they're looking for more quickly."

    Friday, March 9, 2012 1:21 PM