Hello,
I wrote the following JS so I can remove leading zeroes from an Alphanumeric field. However when I run the code - the field is not dropping the leading zeroes.
Instead I get the same value. I feel like I'm missing something. The field I'm loading is a string value, but it looks like the replace is being ignored.
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @montezh2001
the type of your ''res'' variable is xml and the replace function works only on string variables. You have to convert your xml variable to a string one like this :
var res = results[0].@image1.toXMLString();
result :
Br,
Amine
Views
Replies
Total Likes
Hello @montezh2001
the type of your ''res'' variable is xml and the replace function works only on string variables. You have to convert your xml variable to a string one like this :
var res = results[0].@image1.toXMLString();
result :
Br,
Amine
Views
Replies
Total Likes
This worked. Thank you. I knew I was missing something small.
Thank you so much!
I also ran it this way based on a recommendation, and this worked as well.
var res = new String(results[0].@image1)
@Amine_Abedour Ok..last question. When I create the instance.var and write it out in an Enrichment, I'm only seeing it output the last record only and appending it to every record. How do I get it to write out all the records?
Views
Replies
Total Likes
Something like this would work for you :
var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select"> <select> <node expr="@id"/> //or any identifier of the workflow's temporary table <node expr="@image1"/> </select> </queryDef>); var results = query.ExecuteQuery(); for each( var tmp in results){ var res = tmp.@image1.toString(); res = res.replace(/^0+/,''); xtk.session.Write(<{vars.targetSchema.split(':')[1]} _operation="update" _key="@id" xtkschema={vars.targetSchema} id={tmp.@id} image1={res}/>); // update each row of your temp schema with the right res }
No need for Enrichment after that.
Br,
Amine
Views
Replies
Total Likes
This worked PERFECTLY!!! Thank you again. I'm new to coding in JS and knew I was missing something. Thank you again for your help.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies