How to get/run the content/script of a personalized block in javascript | Community
Skip to main content
New Participant
December 19, 2022
Solved

How to get/run the content/script of a personalized block in javascript

  • December 19, 2022
  • 1 reply
  • 1178 views

my code to get the content of personalization block :

var personalizationBlock = NLWS.xtkQueryDef.create(
<queryDef schema="nms:includeView" operation="select">
<select>


<node expr="[source/text]" allias="script"/>
</select>
<where>

<condition expr = {"@name = "+strSender+" "} />

</where>
</queryDef>
);
var res = personalizationBlock.ExecuteQuery();

logInfo("Script: "+res.toXMLString());
var test= res.getElementsByTagName("source")[0].getElementsByTagName("text").data;
logInfo("test : "+test);

 

I am getting the query response as below:

<includeView-collection>
<includeView>
<source>
<text>

<![CDATA[my script here]]>

</text>
</source>
</includeView>
</includeView-collection>

 

I need to get the script without the CDATA which is coming undefined now.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Amine_Abedour

Hello @melinam63825268 ,

 

First you have a typo in your query, 'alias' is with one 'l' not two.

 

Try with the code below :

var personalizationBlock = NLWS.xtkQueryDef.create( <queryDef schema="nms:includeView" operation="select"> <select> <node expr="[source/text]" alias="script"/> </select> <where> <condition expr = {"@name = '"+strSender+"'"} /> </where> </queryDef> ); var res = personalizationBlock.ExecuteQuery(); var data = res.getFirstElement("includeView").getValue("script"); logInfo("data : "+data);

 

Br,

Amine

1 reply

Amine_Abedour
Amine_AbedourAccepted solution
New Participant
December 19, 2022

Hello @melinam63825268 ,

 

First you have a typo in your query, 'alias' is with one 'l' not two.

 

Try with the code below :

var personalizationBlock = NLWS.xtkQueryDef.create( <queryDef schema="nms:includeView" operation="select"> <select> <node expr="[source/text]" alias="script"/> </select> <where> <condition expr = {"@name = '"+strSender+"'"} /> </where> </queryDef> ); var res = personalizationBlock.ExecuteQuery(); var data = res.getFirstElement("includeView").getValue("script"); logInfo("data : "+data);

 

Br,

Amine

Amine ABEDOUR
New Participant
December 20, 2022

Thanks a lot :). it worked .