Expand my Community achievements bar.

SOLVED

Read more than one values from Variable in Filtering condtions

Avatar

Level 3

I am trying to pass multiple values from a variable in JavaScript activity into filter condition next activity, however constantly getting an error saying 'res.getElementsByTagName is not a function'.

Can anyone please have a look and help with their valuable input.

The code I am using is:


var winner = xtk.queryDef.create(<queryDef schema="nms:delivery" operation="select">
<select>
<node expr="@id"/>
<node expr="@internalName"/>
<node expr="@state"/>
<node expr="@created"/>
</select>
<where>

<condition expr={("@state = '95' ")}/>

</where>
<orderBy>
<node expr="[@created]" sortDesc="true" />
</orderBy>
</queryDef>);

res = winner.ExecuteQuery();

var resultArray = new Array();

var result= res.getElementsByTagName("nms:delivery");

for each (var row in result)
{
resultArray.push("'"+row.getAttribute("@internalName")+"'");
//resultArray.push("'"+row.@internalName+"'");

}

vars.finalResult = resultArray.join(",").slice(1,2,3,4,5);

logInfo("The Internal Names are" + vars.finalResult);

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @mustufam5967803 ,

 

why do not you iterate res variable immediately and use values?

 

for each (var row in res)
{
resultArray.push(row.@internalName);

}

 

Generally, you must convert output to the DOM object first in order to avoid error if I am not wrong:

res = winner.ExecuteQuery();

res = DOMDocument.fromXMLString(res);

and then to use

var result= res.getElementsByTagName("nms:delivery");

 

Regards,

Milan

 

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

Hi @mustufam5967803 ,

 

why do not you iterate res variable immediately and use values?

 

for each (var row in res)
{
resultArray.push(row.@internalName);

}

 

Generally, you must convert output to the DOM object first in order to avoid error if I am not wrong:

res = winner.ExecuteQuery();

res = DOMDocument.fromXMLString(res);

and then to use

var result= res.getElementsByTagName("nms:delivery");

 

Regards,

Milan

 

Avatar

Level 3

Hi milanv69354962,

Thank you for your prmopt response, it worked :). 
One more quick help needed, I want select top 5 records however it is taking them all.
Also, I want to pass the values into split activity and "is Included in" but getting an error. The variable I am passing here is  $(vars/@finalResult).

Avatar

Community Advisor

Hi @mustufam5967803,

 

try to add parameter line Count to your query and field for sorting by.

 
 
 
 
 
 

js.PNG

 

This should work for you.

Regarding reading variable in split please check: https://helpx.adobe.com/uk/campaign/kb/instance-variable-in-workflow.html

 

Regards,

Milan

Avatar

Level 3

Thanks @Milan_Vucetic 

One last help, when i am paasing data into variable in split acitvity it is giving an error saying unable to parse the expression.

 

Avatar

Community Advisor

Hi @mustufam5967803

 

I do not have enough information to help you about mentioned.

You can use JS instead of Split node and create several branches.

Example code (change it per your needs):

 

var test= 1;
if(test> 1){
task.postEvent(task.transitionByName("branch1"));

} else {
task.postEvent(task.transitionByName("branch2"));
};

 

Regards,

Milan