Announcement

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

    how to get single quoted string from $criteria

    1. SmartClient Version: v8.2p_2012-05-17/Enterprise Deployment (built 2012-05-17)

    2. Internet Explorer 7

    3. Using XML datasource with SQL templating and customSQL

    I have a multi selectItem that I want to use inside an IN clause in the datasource.

    Datasource looks like:

    Code:
    #if ($criteria.PROJECT_DEF) and o.ori_project_def IN ($criteria.PROJECT_DEF)  #end
    Stacktrace shows output:
    Code:
    and o.ori_project_def in ('[Z1C1BBAR, Z1S1FNJE]')
    Dev Console DSRequest:
    Code:
    {
        "dataSource":"rtnOrgStructure", 
        "operationType":"fetch", 
        "componentId":"isc_MPMScreen_0_reportGrid", 
        "data":{
            "BUYER_PATHCODE":"00001", 
            "plant_pathcode":"0001", 
            "entityId":"SG260", 
            "PROJECT_DEF":[
                "Z1C1BBAR", 
                "Z1S1FNJE"
            ]
        }, 
        "startRow":0, 
        "endRow":75, 
        "textMatchStyle":"exact", 
        "resultSet":[ResultSet ID:isc_ResultSet_3 (created by: isc_MPMScreen_0_reportGrid)], 
        "callback":{
            "caller":[ResultSet ID:isc_ResultSet_3 (created by: isc_MPMScreen_0_reportGrid)], 
            "methodName":"fetchRemoteDataReply"
        }, 
        "willHandleError":true, 
        "showPrompt":true, 
        "prompt":"Finding records that match your criteria...", 
        "oldValues":{
            "BUYER_PATHCODE":"00001", 
            "plant_pathcode":"0001", 
            "entityId":"SG260", 
            "PROJECT_DEF":[
                "Z1C1BBAR", 
                "Z1S1FNJE"
            ]
        }, 
        "clientContext":{
            "requestIndex":1
        }, 
        "requestId":"rtnOrgStructure$6279"
    }
    RPCRequest
    Code:
    {
        "actionURL":"http://localhost:8888/msft/isomorphic/IDACall", 
        "showPrompt":true, 
        "prompt":"Finding records that match your criteria...", 
        "transport":"xmlHttpRequest", 
        "promptStyle":"cursor", 
        "bypassCache":true, 
        "data":{
            "criteria":{
                "BUYER_PATHCODE":"00001", 
                "plant_pathcode":"0001", 
                "entityId":"SG260", 
                "PROJECT_DEF":[
                    "Z1C1BBAR", 
                    "Z1S1FNJE"
                ]
            }, 
            "operationConfig":{
                "dataSource":"rtnOrgStructure", 
                "repo":null, 
                "operationType":"fetch", 
                "textMatchStyle":"exact"
            }, 
            "startRow":0, 
            "endRow":75, 
            "componentId":"isc_MPMScreen_0_reportGrid", 
            "appID":"builtinApplication", 
            "operation":"rtnOrgStructure_fetch", 
            "oldValues":{
                "BUYER_PATHCODE":"00001", 
                "plant_pathcode":"0001", 
                "entityId":"SG260", 
                "PROJECT_DEF":[
                    "Z1C1BBAR", 
                    "Z1S1FNJE"
                ]
            }, 
            "streamResults":null, 
            "exportToFilesystem":null, 
            "exportToClient":null
        }
    }
    How can I get it to generate:
    'Z1C1BBAR', 'Z1S1FNJE' instead of '[Z1C1BBAR, Z1S1FNJE]'
    Last edited by vtran27; 30 May 2012, 17:10.

    #2
    Always show the complete server output for the request, as the forums prompt you to. Otherwise, as with this case, key details are omitted.

    Comment


      #3
      I apologize for that. I reposted the complete DSRequest and RPCRequest above.

      Comment


        #4
        By server-side log we mean the log4j-style output that is logged by server-side classes as the request is processed.

        This is going to show how the data looks once the server has received it.

        Assuming it shows that the value is arriving on the server intact as a Java List, you basically need to use Velocity iterators to iterate over it in order to produce the SQL you want. Two other options are to use the IN_SET AdvancedCriteria operator instead, or form the SQL in Java and provide it to Velocity via dsRequest.addToTemplateContext().

        Comment


          #5
          Thank you for the suggestions. I ended up pre-processing the array into a single quoted, coma delimited string in javascript before calling the fetch. Then in the datasource, I used $rawValue.criteria.fieldName for my in clause

          Function to create String for in clause:
          Code:
          function mkInClause(arr) {
          	var str = "";
          	if (!arr) {
          		return str;
          	}	
          	for (var i=0; i < arr.length; i++) {
          		var element = "'" + arr[i] + "'";
          		if (i==0) {
          			str += element;
          		} else {
          			str += "," + element;	
          		}		
          	}
          	return str;
          }
          Calling code
          Code:
          	// create an string to use for the IN clause in Datasource
          	var valuesManager = this.searchOptions.searchValues;
          	var projDef = valuesManager.getValue("PROJECT_DEF");	
          	var projDefInClause = mkInClause(projDef);;
          	valuesManager.setValue("PROJECT_DEF_IN_CLAUSE", projDefInClause);
          
          	// call fetch
          	this.reportGrid.fetchData(valuesManager.getValues());
          Velocity code to use in Datasource
          Code:
          #if ($criteria.PROJECT_DEF) and o.ori_project_def in ($rawValue.criteria.PROJECT_DEF_IN_CLAUSE)  #end
          Last edited by vtran27; 31 May 2012, 17:41.

          Comment

          Working...
          X