Expand my Community achievements bar.

SOLVED

Send target to a transition from advanced javascript

Avatar

Level 7

Hello, i have an advanced javascript code like this.

Heku__0-1680086889085.png

I have 3 transitions, and the 15 targets go to the 3 transitions, but i would like the language == "es" to go to the transition Es, and the language == "en" to go to the transition En, how can i do it?

Heku__1-1680087023550.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @alnavarg 

 

I tried running a similar code and got the desired results.

var query = xtk.queryDef.create(    
  <queryDef schema={vars.targetSchema} operation="select">    
    <select>    
      <node expr="@id"/>    
      <node expr="@lastName"/>    
    </select>    
  </queryDef>    
);    
var resultSet = query.ExecuteQuery(); 
for each (var row in resultSet) 
{   
  var condition = row.@lastName;
  logInfo(condition);
  if(condition == 'Test')
{
   task.postEvent(task.transitionByName('english')); 
} else {
  task.postEvent(task.transitionByName('other'));
} 
}

 

When you look in the transitions it will show all the records but if you do a log in individual END activities, you can see the desired no. of records being processed.

AkshayAnand_0-1680096896678.png

 

AkshayAnand_1-1680096923674.png

 

AkshayAnand_2-1680096952248.png

As per my record, only one record satisfied the English transition condition hence one log for English END activity.

I would request you to once try logging in the END activity and see if the desired results are being processed.

 

Regards

A

 

View solution in original post

16 Replies

Avatar

Level 3

In your for each loop you need to declare the language variable.
Instead of:

language = e.language

 try:

var language = e.language

 

Avatar

Correct answer by
Community Advisor

Hi @alnavarg 

 

I tried running a similar code and got the desired results.

var query = xtk.queryDef.create(    
  <queryDef schema={vars.targetSchema} operation="select">    
    <select>    
      <node expr="@id"/>    
      <node expr="@lastName"/>    
    </select>    
  </queryDef>    
);    
var resultSet = query.ExecuteQuery(); 
for each (var row in resultSet) 
{   
  var condition = row.@lastName;
  logInfo(condition);
  if(condition == 'Test')
{
   task.postEvent(task.transitionByName('english')); 
} else {
  task.postEvent(task.transitionByName('other'));
} 
}

 

When you look in the transitions it will show all the records but if you do a log in individual END activities, you can see the desired no. of records being processed.

AkshayAnand_0-1680096896678.png

 

AkshayAnand_1-1680096923674.png

 

AkshayAnand_2-1680096952248.png

As per my record, only one record satisfied the English transition condition hence one log for English END activity.

I would request you to once try logging in the END activity and see if the desired results are being processed.

 

Regards

A

 

Avatar

Level 5

alnavarg_0-1680103778385.png

 

alnavarg_1-1680103341020.png

alnavarg_3-1680103695848.png

We don´t know where the problem is.

Could you analyse the code and say me where is the error.

Thanks

Avatar

Community Advisor

Hello @alnavarg @Heku_ 

 

What is the output of logInfo(condition) ?


     Manoj
     Find me on LinkedIn

Avatar

Community Advisor

Hi @alnavarg 

 

As the log suggests the filtering is happening, Could you please try adding the END activity in the transitions and add a log in each of them. Then we could see as how many times the respective END activity is being activated.

Something like below.

AkshayAnand_0-1680159517511.png

 

 

Regards,

A

Avatar

Community Advisor

Hello @alnavarg the activity is not creating a temporary table and that is why the data is not available in the arrows.


     Manoj
     Find me on LinkedIn

Avatar

Level 5

If i want to do what you said what code i need to write?

 

What I want to do is to make a javascript that takes from the recipients the language and creates a delivery by language and sends it to the recipients that have the same language.

 

@_Manoj_Kumar_ @AkshayAnand @dwnuk 

Avatar

Community Advisor

Hi @alnavarg 

 

If your use case is to send delivery based on the recipient language, then you can use the SPLIT activity to assign different segment codes to different target audience and use JSSP (<% targetData.SegementCode) %>) and call different personalization blocks containing the email content. 

 

Regards,

A

Avatar

Level 5

I want to do everything through javascript if possible, I do NOT want to use split,
I want a Js:
-I want to filter by languages
-Then that js will choose a delivery with that language and relate it to the delivery.
-That this delivery contains all the necessary to be able to send: To, Subject and the TEMPLATE.
-Finally send it to the filtered recipients.

Thanks

 

@AkshayAnand @_Manoj_Kumar_ @dwnuk@Heku_ @CampaignerForLife

Avatar

Community Advisor

Hi @alnavarg 

 

You can use the nms.delivery.SubmitNotification function to send out the delivery where you can define the targets.

 

Regards

A

 

Avatar

Level 7

Hello, you can use the method nms.delivery.SubmitNotification() with the template internal name and the XML target as params

 

 

https://experienceleague.adobe.com/developer/campaign-api/api/sm-delivery-SubmitNotification.html


You can find more info here