Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to test the criteria value in Velocity?

    I tried to test the value of a criteria with Velocity in a custom SQL tag:
    Code:
    		<operationBinding operationType="fetch">
    			<customSQL>
    (...)
    #if ($criteria.statut == 'Active' || $criteria.statut == 'Inactive')
    (some sql)
    #end
    (...)
    #if ($criteria.statut == 'Active')
    (some sql)
    #elseif ($criteria.statut == 'Inactive')
    (...)
    #end
    			</customSQL>
    		</operationBinding>
    I tried:
    - Using ' or " or escaping with &quot; or &apos;
    - Using $dsRequest.criteria

    When I use the operator !=, it trigger the first if. So my guest is that the velocity variable have something in it, but not active/inactive.

    I trace the fetch, who seem ok:
    Code:
    {
        "actionURL":"http://127.0.0.1:8888/csmpapp/sc/IDACall", 
        "showPrompt":true, 
        "prompt":"Recherche des enregistrements correspondant à vos critères...", 
        "transport":"xmlHttpRequest", 
        "promptStyle":"dialog", 
        "bypassCache":true, 
        "data":{
            "criteria":{
                "operator":"and", 
                "criteria":[
                    {
                        "fieldName":"statut", 
                        "operator":"equals", 
                        "value":"Active"
                    }
                ]
            }, 
            "operationConfig":{
                "dataSource":"recherche", 
                "repo":null, 
                "operationType":"fetch", 
                "textMatchStyle":"exact"
            }, 
            "componentId":"isc_ListGrid_0", 
            "appID":"builtinApplication", 
            "operation":"recherche_fetch", 
            "oldValues":{
                "operator":"and", 
                "criteria":[
                    {
                        "fieldName":"statut", 
                        "operator":"equals", 
                        "value":"Inactive"
                    }
                ]
            }
        }
    }
    Anyone got some idea how we can do this?

    Thank again for your time!

    #2
    I just tried the rawValue without success:
    Code:
    #if ($rawValue.criteria.statut == 'Active')

    Comment


      #3
      If you changed your client-side code around so that it generated simple Criteria rather than AdvancedCriteria your current approach would work. The specific criteria you are passing here do not require AdvancedCriteria.

      If you need to do this with AdvancedCriteria, basically, look at the JSON structure of the AdvancedCriteria you see in the logs and think of it as equivalent Java Collections - Object -> Map, Array -> List. Then it's just normal Velocity to access values, eg, $criteria.criteria[0].value.

      However, this is a somewhat messy and fragile way of doing this. If you have two different queries with little in common, consider using dsRequest.operationId to switch between the variants instead.

      Comment


        #4
        Thank, very helpful answer know at least I know what is the problem!

        I have 20 more field that I need AdvancedCriteria.

        When I switch one of them to ICONTAIN, all the criteria seem to switch to AdvancedCriteria with the form.getValuesAsCriteria().

        Is there any way to mix up criteria type (simple + advance)?

        After generating the criteria with getValuesAsCriteria, can I can add simple Criteria to the mix?

        Comment


          #5
          The simple Criteria format has no way to specify an operator, so all fields must use the same operator, which is settable as the textMatchStyle on the dsRequest.

          You can combine simple Criteria and AdvancedCriteria with DataSource.combineCriteria(). But the result will always be AdvancedCriteria of course.

          Comment

          Working...
          X