Expand my Community achievements bar.

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
Community Advisor

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

2 Replies

Avatar

Correct answer by
Community Advisor

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