Announcement

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

    OperationBinding whereClause issue

    SmartClient_v111p_2017-12-16_PowerEdition

    Can i pass in multiple values into the $criteria for a single field to show in the IN clause inside of the whereClause
    for example i have the following operationBinding in the ds.xml file:
    Code:
        <operationBindings>
              <operationBinding operationType="fetch" operationId="getPendingRequests">
                  <whereClause> Request.CurrentStatusKey != $criteria.CurrentStatusKey 
                    #if ($criteria.StatusKeys) AND Request.CurrentStatusKey in ($criteria.StatusKeys) #end
                    #if ($criteria.UserKey) AND Request.requestKey in (SELECT RequestKey FROM cfm.Investigation i JOIN cfm.InvestigationTarget it on i.InvestigationKey = it.InvestigationKey WHERE it.UserKey = $criteria.UserKey)  #end
                </whereClause>
                <orderClause> CurrentStatusKey </orderClause> 
            </operationBinding>
        </operationBindings>
    and this is the JS side
    Code:
        var crit = {CurrentStatusKey:7};
        var fetchOperationId = "getPendingRequests";
        if (!CRM_REQUEST_MANAGER && FILTER_BY_STATUS)
        {
            crit.StatusKeys = Array.from(CURRENT_USER_RIGHTS.values());
            if (CRM_INESTIGATION && FILTER_INVESTIGATION_TARGET)
            {
                crit.UserKey = userKey;
            }
    
        }
        Requests.fetchData(crit,null,{operationId:fetchOperationId});
    but it seems like the $criteria is expecting a single value since i see it the backend putting single quotes around my array
    i couldn't find an example using the whereClause unless i use advancedCriteria but not sure if i can do both at the same time
    any suggestions would be appreciated

    thanks

    #2
    Looks Like i have found the solutions after digging a into forums and checking google searches looks like i missed the VTL in the Custom Querying Overview.
    here is the solution for other users in case some one else comes across is

    Code:
        <operationBindings>
              <operationBinding operationType="fetch" operationId="getPendingRequests">
                  <whereClause> 
                    Request.CurrentStatusKey != $advancedCriteria.CompletedStatusKey
                    #if ($advancedCriteria.CurrentStatusKey) AND Request.CurrentStatusKey IN (#foreach($status in $advancedCriteria.CurrentStatusKey)#if($$velocityCount>1),#{end}${status}#end) #end
                    #if ($advancedCriteria.UserKey) AND Request.requestKey in (SELECT RequestKey FROM cfm.Investigation i JOIN cfm.InvestigationTarget it on i.InvestigationKey = it.InvestigationKey WHERE it.UserKey = $advancedCriteria.UserKey)  #end
                </whereClause>
                <orderClause> CurrentStatusKey </orderClause> 
            </operationBinding>
        </operationBindings>
    
    
        var crit ={
                  _constructor:"AdvancedCriteria",
                    operator:"and",
                    criteria:[
                        // this is a Criterion
                        { fieldName:"CompletedStatusKey", operator:"notEqual", value:7}
                    ]
                };
        var fetchOperationId = "getPendingRequests";
        if (!CRM_REQUEST_MANAGER && FILTER_BY_STATUS)
        { 
            var criteria =  
                {
                  _constructor:"AdvancedCriteria",
                    operator:"and",
                    criteria:[
                        // this is a Criterion
                        { fieldName:"CurrentStatusKey", operator:"inSet", value:Array.from(CURRENT_USER_RIGHTS.values())}
                    ]
                }
            if (CRM_INESTIGATION && FILTER_INVESTIGATION_TARGET)
            {
                criteria =  
                {
                  _constructor:"AdvancedCriteria",
                    operator:"and",
                    criteria:[
                        // this is a Criterion
                        { fieldName:"CurrentStatusKey", operator:"equals", value:Array.from(CURRENT_USER_RIGHTS.values())},
                        { fieldName:"UserKey" , operator:"equals", value:userKey}
                    ]
                }        
            }
            crit = isc.DataSource.combineCriteria(criteria, crit);        
        }
        Requests.fetchData(crit,null,{operationId:fetchOperationId});

    Comment

    Working...
    X