- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 07:37 AM
Hi All,
I hope someone can help me.
I have a transform field map script that is not working correct. What I am trying to do is iterate though the source kunden number and for all matches that are found in core company table the corresponding sys_id is added to u_company field but the script iterates and has the same company sys id for every record. In the log file it records same sys_id but also each unique kunden number.
Need to add the field is a reference field and the Referenced value field name: u_company
Any idea why it is not return the unique sys_id for each record?
answer = (function transformEntry(source) {
var gr1 = new GlideRecord("core_company");
gr1.addQuery("u_company",source.u_kundennr_.toString());
gr1.query();
if(gr1.next()){
target.u_company = gr1.sys_id;
}
gs.log("Kundennummer: " + source.u_kundennr_);
gs.log("sys_id von ?: " + gr1.sys_id);
return ""; // return the value to be put into the target field
})(source);
Many Thanks,
Ellie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 08:52 AM
can you try like this
var gr1 = new GlideRecord("core_company");
gr1.addQuery("nr",source.u_kundennr_.toString());
gr1.query();
if(gr1.next()){
target.u_company = gr1.sys_id;
// put your logs here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 08:54 AM
Hi Ellie,
Try returning some value. Example
answer = (function transformEntry(source) {
var gr1 = new GlideRecord("core_company");
gr1.addQuery("u_company",source.u_kundennr_.toString());
gr1.query();
if(gr1.next()){
target.u_company = gr1.sys_id;
}
gs.log("Kundennummer: " + source.u_kundennr_);
gs.log("sys_id von ?: " + gr1.sys_id);
return gr1.sys_id; // returning the sys_id
})(source);
"answer" needs some value to be returned else it won't work.
Hope this helps
Regards,
Dhruv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 09:21 AM
Thanks Chandan,
It is resolved now.
Ellie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 08:59 AM
Your script should be:
answer = (function transformEntry(source) {
var response = ""; //the value that will be returned and set in the target field
var gr1 = new GlideRecord("core_company");
gr1.addQuery("u_company", source.getValue("u_kundennr_"));
gr1.query();
if(gr1.next()){
response = gr1.getValue("sys_id");
}
gs.log("Kundennummer: " + source.u_kundennr_);
gs.log("sys_id von ?: " + gr1.sys_id);
return response; // the answer is returned here
})(source);
That will return the sys_id of the Company record to the "answer" variable which in turns sets the value of the target field. What you were doing earlier was setting the value of target.u_company but then clearing it out with "return ''".
You also want to force the returned value to a string on line 8 with "getValue" instead of a pointer to the data, which can change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 09:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2017 09:20 AM
Hi Jim,
Thank you for helping. I is sorted now the reference field has u_compnay al along which is correct.
I specified the incorrect field in my addQuery and I did not see this anymore but Nish got me in the right direction.
Many Thanks
Ellie