Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

The 4th edition of the Campaign Community Lens newsletter is out now!
SOLVED

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

Avatar

Level 2

melinam63825268_0-1671453337775.png

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.

melinam63825268_0-1671453770124.png

 

1 Accepted Solution

Avatar

Correct answer by
Level 4

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

View solution in original post

0 Replies

Avatar

Correct answer by
Level 4

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

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now