Add a where element to queryDef through javascript.

Avatar

Avatar

rahulg1930481

Avatar

rahulg1930481

rahulg1930481

25-06-2019

var query =  <queryDef schema = "temp:enrich32" operation="select">

                             <select>

                                 <node expr="@firstName"/>

                            </select>

                            <where>

                             </where>

                    </queryDef>

var condition =   <condition boolOperator="AND">

                            <condition>

                            <condition boolOperator="OR" internalId="0" expr="@gender = 'M'"/>

                            <condition boolOperator="OR" internalId="1" expr="@gender = 'F'"/>

                           </condition>

I want to add the condition into the where in query in a javascript activity.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Florian_Courgey

MVP

Avatar

Florian_Courgey

MVP

Florian_Courgey
MVP

27-06-2019

Hi,

You can use Javascript JXON then, it's easier. Consider the following workflow:

20190627-104703-screenshot-1.jpg

Activity 1:

var query = {queryDef: {

  schema: "temp:enrich32",

  operation: "select",

  select:{ node: [

    {expr: "@firstName"}

  ]},

  where:{}

}};

vars.query = JSON.stringify(query); // string

Activity 2:

var query = JSON.parse(vars.query); // json

var condition = {

  boolOperator: 'AND',

  condition:[

    {boolOperator: 'OR', internalId: "0", expr: "@gender = 'M'"},

    {boolOperator: "OR", internalId: "1", expr: "@gender = 'F'"},

  ],

};

query.queryDef.where.condition = condition; // add condition to the query

You may use directly query as a JXON (see Using XML ) or convert it with "DOMDocument.fromJXON(query).toXMLString()" which outputs:

<?xml version='1.0'?>

<queryDef operation="select" schema="temp:enrich32">

     <select>

          <node expr="@firstName"/>

     </select>

     <where>

          <condition boolOperator="AND">

               <condition boolOperator="OR" expr="@gender = 'M'" internalId="0"/>

               <condition boolOperator="OR" expr="@gender = 'F'" internalId="1"/>

          </condition>

     </where>

</queryDef>

Regards

Answers (2)

Answers (2)

Avatar

Avatar

Florian_Courgey

MVP

Avatar

Florian_Courgey

MVP

Florian_Courgey
MVP

26-06-2019

Hi,

You can do query.where.appendChild(condition)

See this blog post for more examples

Regards

Avatar

Avatar

rahulg1930481

Avatar

rahulg1930481

rahulg1930481

26-06-2019

Hi floriancourgey

I have the condition in the string format which is passed from another javascript activity. when I try to append the conditon to the query , the '<' and '>' symbols in the condition are replaced with '&lt' and '&gt' symbols. Because of this the query is not working. Is there any way to add the condition.

Thanks and Regards

Rahul G