Expand my Community achievements bar.

Javascript xtk.session.Write - Data not updating

Avatar

Level 4

Hello, 

 

I created this script to update a field with a reformatted date. 

montezh2001_0-1647280472383.png

Howeever, when I look at my output data, the field is still NULL, even though I can see from the DisplayLogs that I'm creating the data. 

montezh2001_5-1647280703679.png

 

montezh2001_4-1647280678868.png

 

 

 

Please advise what I'm missing. 

 

17 Replies

Avatar

Community Advisor

Hello @montezh2001 

 

The issue is with how the xtk.session.write method is written.

 

<vars.targetSchema is not correct syntax. Replace it with correct syntax.

 

 

 

 


     Manoj
     Find me on LinkedIn

Avatar

Level 4

Manoj, 

 

Sorry, I'm not well-versed on JS. However, even when I change my code to read from the schema name, I still get no output: 

montezh2001_0-1647350225142.png

 

Please advise

 

Avatar

Employee

Date fields are typically of the UTC (Universal Time Code) type and must conform with that format.  You cannot reformat a date and then write it back into such a field as it no longer matches the data type.  Reformatted dates are typically used to write the date into another field, or as target.data in a delivery or into an output file.

Avatar

Level 4

As you can see in my code that I'm reformatting the date into a string (MMMYYYY) and placing it into a field that is a string. 

 

montezh2001_0-1647372161545.png

So still not sure why I can't see data. I've even tried the following code - and still get no results. 

montezh2001_1-1647372295381.png

 

 

Avatar

Community Advisor

Hello @montezh2001,

 

montezh2001_0-1647280472383.png

I see two issues in your xtk.session.Write, the "vars.targetSchema" should be " {vars.targetSchema.split(':')[1]} ", and the identifier used to update your rows. As i understand from your request, the identifier of your temporary table is "clientId" and not "id", so your script should look like this :

var query = xtk.queryDef.create(
              <queryDef schema={vars.targetSchema} operation="select">
                <select>
                  <node expr="@clientId"/> //or any identifier of the workflow's temporary table
                  <node expr="@contractIssueDate"/>
				  <node expr="@MMMYYYYDate"/>
                </select>
                </queryDef>);
				
				
var results = query.ExecuteQuery();


for each( var tmp in results){
  var res = tmp.@contractIssueDate;
  var Date1 = formatDate(res,"%B%Y").toString();
  
  logInfo("MMMDate: "+Date1);
  
  xtk.session.Write(<{vars.targetSchema.split(':')[1]} _operation="update" _key="@clientId" xtkschema={vars.targetSchema} clientId={tmp.@clientId} MMMYYYYDate={Date1}/>); 
}

Br,

 

Amine

Avatar

Level 4

Thank you for replying, but this is returning an error. 

montezh2001_0-1647392881376.png

 

Here is a view of my WF: 

montezh2001_1-1647392921258.png

 

I'm reading in a List, adding the @policyTenureMMMYYYY field in my Enrichment, and then trying to run the JS code to create/populate the @policyTenureMMMYYYY field. 

 

Not sure why this will not work in Adobe, but this is beyond frustrating as either I try xtk.session.Write or sqlExec - I get the same results. 

 

I've stated before that I'm not proficient in JS, but this code has worked for me before as I needed it to remove leading 0's from a field and output the new field. Now it's if ACC doesn't recognize the code and can't read from the data schema feeding into the JS. 

Did something change in ACC that I'm not aware of? 

Avatar

Level 4

Also - here's the log of the Date field I'm creating - 

montezh2001_2-1647393986283.png

 

So the field is creating - just not writing out. 

Avatar

Community Advisor

Hi @montezh2001 , Can you please share the complete js code once again, how it looks after making the above suggested changes?

 

Thanks,

Ishan

Avatar

Level 4

Here's the latest iteration. It contains both codes I've tried. 

montezh2001_0-1647520728747.png

 

Avatar

Community Advisor

Hi @montezh2001 , can you please also paste the complete error log of this activity when run with this code? Maybe also the interim results before this activity, and the enrichment configuration where you added that field which you are trying to update?

 

Thanks,

Ishan

Avatar

Level 4

Hello, 

 

So I am able to get them to run with no error. Previous errors were all coding issues. But I will paste the log and Enrichment. 

montezh2001_0-1647530230425.png

montezh2001_1-1647530566722.png

 

Avatar

Community Advisor

Hi @montezh2001,

So I can see from your enrichment that the matchKey itself is made up of two fields.

Can you may be add these two fields in your select expression, and then use them as a composite key in your xtk.session.Write method? Like this below:

 

_key="@clientId,@contractId" and use both of them in your Write call.

 

So it would look something like this:

_key="@clientId,@contractId" clientId={tmp.@clientId} contractId={tmp.contractId}

 

This should resolve your problem. Let me know if that worked.

 

Thanks,

Ishan

Avatar

Level 4

Ishan, 

 

Still no results. It's a head scratcher for sure. The following is the revised JS Code, the log showing I'm creating the date, and the data field from the schema not being populated. I made one change to the JS Code and I'm now going to pick up the Date1 field. 

montezh2001_2-1647534202541.png

 

montezh2001_3-1647534241226.png

montezh2001_4-1647534471616.png

 

 

 

Avatar

Community Advisor

Hi @montezh2001,

Does the targetSchema has contractId and clientId coming from the database fields, or are they also derived from some other expression? Does your targetSchema has any other key fields?

It should work this way for sure.

 

Can you try one thing? Try to set some static value in the field when you add it in the enrichment. Later in your code it should get updated. If it still does not get updated, can you check the clientId and contractId values in the resulting data set?

 

Thanks,

Ishan

Avatar

Level 4

I'm reading in a List, so the ClientId and ContractId are coming from there. I'll try your suggestion. Give me 15 minutes. 

Avatar

Level 4

Ishan, 

 

I filled the Policy field with 'Null' and then ran the WF again. I'm getting results, but not for every record now. And the results seems to be inaccurate. Below is an example of a duplicate where I should have two different Policy Tenures.

 

montezh2001_0-1647537769805.png

montezh2001_1-1647538579298.png

 

So almost there. However, the majority of the file still is not updating. 

Avatar

Community Advisor

Hi @montezh2001,

Is the list of type "File" or is it linked to nms:recipient? Also, in case you are reading from a list, maybe it would work if you could update the related sql table of this list (if it is of type "File") and add this new field to the sql table. Then directly update data into this table using an SQL statement.

 

If it is linked to nms:recipient, then may be try querying on nms:recipient as the targeting dimension to get the recipients who are present in that list, and also adding the data from that list into your targetSchema via enrichment (I did not try this approach so far). Try and let me know.

 

Thanks,

Ishan