Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Storing different values containing commas (,) to a GlideList using transform Maps

Azfar
Kilo Explorer

Hi Friends,
I am configuring Software Licenses form. I have a field called as Entitled Location which is a " Glide List " ( the one with a lock icon ).
i am migrating data using staging tables & transform maps. When i transfer data to this field ( Entitled Location ), it delimits the values by comma (,).
The irony is my data does contain comma. Here is an example :

Value to be migrated : Perth,Australia.

However, if i don't customize this, it gets stored as 2 values : Perth & Australia . Understand that since glidelist delimits values by " , " by default.

Next, I write a Transform Script in my transform maps to delimit the values by Semi-colon ( ; ) and query the locations table to only give valid values [ if i don't query, Glide list seems to take anything ( i really mean anything - even if its not a valid location)].

Here is my Code :



var locations=source.u_entitled_location; //taking locations from staging table
var gr = new GlideRecord('cmn_location');
var temp= new Array();
temp=locations.split(";");//delimiting by ; since multiple values have ; inbetween in my data
var length=temp.length;
for(var i =0;i<temp.length;i++)
{
var check = temp<i>;
var locationName = check.toString();
gr.addQuery('name',locationName);
gr.query(); // querying the location table to check whether its a valid value or not
while(gr.next())
{
target.u_entitled_location=gr.sys_id;
}
gr.update();
}



The problem here is that only one value gets transformed in my Target table.

Example ( Value in Staging table ) --> Perth,Australia;Sydney,Australia

Current Value in Target Table : Perth,Australia

Expected Value : Perth,Australia,Sydney,Australia where Perth,Australia is 1st value & Sydney,Australia is 2nd value


Though it delimits at ; and gives me a proper value, it gives only the value at the first position & ignored Sydney,Australia

Can someone have a look & help me out with this ? Thanks a lot in advance guys!

7 REPLIES 7

gaidem
ServiceNow Employee

It's working for me so I'm not really sure what to say. Put some debug stuff in to see where it's failing.


Thanks Matt.
I tried it in a different way & it worked.
Thought it's worth to post my code. Here it is :



locs = [];
var locations=source.u_entitled_location; //taking locations from staging table
temp=locations.split(";");//delimiting by ; since multiple values have ; inbetween in my data
var length=temp.length;
for(var i=0;i<length;i++){
var check = temp<i>;
var locationName = check.toString();
var gr = new GlideRecord('cmn_location');
gr.addQuery('name',locationName);
gr.query();
while(gr.next()){
locs.push(gr.sys_id.toString());
}
}
target.u_entitled_location = locs.toString();


Thanks for your help though! CHeers


Azfar
Kilo Explorer

Unfortunately, I do not have access to the Background Scripts.
I tried it with " On Before " Transform Script