Need Help with Looping in JS for a usecase

Avatar

Avatar
Validate 1
Level 2
akashaj7696
Level 2

Likes

5 likes

Total Posts

29 posts

Correct reply

3 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 1
Level 2
akashaj7696
Level 2

Likes

5 likes

Total Posts

29 posts

Correct reply

3 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile
akashaj7696
Level 2

08-04-2021

Hi Everyone,

 

I have a usecase wherein i need to populate one value to other field. Please see below-

CCT_IDbestZip
ID1 
ID1 
ID1 
ID1 
ID112345
ID1 
ID1 
ID1 
ID1 
ID1 

 

I want to populate the zip - 12345 to all the ID1 rows, I tried a code, mentioned below but didn't get it to work yet.

 

var query=xtk.queryDef.create(
<queryDef schema="temp:union" operation="select" lineCount="10000">
<select>
<node expr="@id"/>
<node expr="@CCT_ID"/>
<node expr="@bestZip"/>
<node expr="@newZip"/>
</select>
</queryDef>);

var result = query.ExecuteQuery();

for each (var rec in result.union){

if (rec.@CCT_ID = rec.@CCT_ID){
if (rec.@bestZip != ""){
var value = rec.@bestZip;
logInfo("The value of zip is: " +value);
}
if (rec.@CCT_ID = rec.@CCT_ID){
if (rec.@bestZip = ""){
var newZip = value;
logInfo("The NewZip Value is:" +newZip);
var update=<union xtkschema="temp:union" _operation="update" _key="@id" id={rec.@id}/>
update.@newZip = newZip;

//Write the results to the session
xtk.session.Write(update);
}
}
}

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar
Boost 5
Employee
denisb91363072
Employee

Likes

9 likes

Total Posts

34 posts

Correct reply

8 solutions
Top badges earned
Boost 5
Affirm 5
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Boost 5
Employee
denisb91363072
Employee

Likes

9 likes

Total Posts

34 posts

Correct reply

8 solutions
Top badges earned
Boost 5
Affirm 5
Boost 3
Boost 1
Affirm 3
View profile
denisb91363072
Employee

24-06-2021

Hi there,

If the ask is to query the temporary table and update the temporary table in return, it's not doable outside JS and you would have to have the column you want to update into the temporary table prior the JS by adding it as Additional Data with an empty value.... From a temp table to itself within the workflow itself require a JS activity...

Hope this helps,

Denis.

Avatar

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

91 likes

Total Posts

287 posts

Correct reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

91 likes

Total Posts

287 posts

Correct reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile
Darren_Bowers
MVP

08-04-2021

Hi @akashaj7696 - I have tried to do this and I found that its easier to write back to another schema than the one you are querying in the queryDef. You can then query the temporary table later in the workflow.

I could never get the xtk.session.Write() function to actually work correctly so I used sqlExec() instead. Be careful if you are using user-input values as its not database-safe doing direct DB writes, so you should sanitize the inputs.

Also, the write operation seems to affect the cursor in the query operation when you need to page the query (i.e. >10000 results). It works fine if you never need to page the query.

There is some more info here:  https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/advanced-workflow-...

Cheers

Darren