Transform script to check the source record exist in target table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 07:43 AM
Hi All,
I had a requirement to check the source field(caller)incident table is exist in the target field(approver)user table (sys_user) if the record is exist then map that field,else keep the target field as empty
How to achieve this using tranform script in field mapping
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 01:41 AM
Hi @Sangeetha8,
This is very easily skipped by the use of an 'onBefore' 'Transform Script'.
See the below screenshot to help visualize and use the following code within the Source Script. (Obviously, check against the appropriate field for your needs. Here I am using the email address)
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 05:56 AM
Hi @Sangeetha8,
Did you see my earlier response? Did this provide the solution? It should have.... how can I help you close this out?
My earlier response:
This is very easily skipped by the use of an 'onBefore' 'Transform Script'.
See the below screenshot to help visualize and use the following code within the Source Script. (Obviously, check against the appropriate field for your needs. Here I am using the email address)
@Sangeetha8 - To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 03:14 AM
Hi Robbie,
Instead of writing onbefore script, I have written a source script
answer = (function transformEntry(source) {
var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('userRecord.name', source.u_approver);
userRecord.query();
if (userRecord.hasNext()) {
if(target.approver==source.u_approver)
{
target.approver = source.u_approver;
gs.log("if loop);
}
else
{
// No user records exist in the target table, set the target field as empty
target.approver = '';
gs.log("user record is empty ");
}
}
})(source);
The log is not working in transform script ,how to write a transform script log.I need to know whether the field is target field (approver) is set to empty if no match is found in user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 03:47 AM - edited 02-08-2024 01:44 AM
Hi @Sangeetha8,
I see a few issues in your script. Please note the highlighted in bold subtle but important changes I've made to help you with scripting moving forward.
answer = (function transformEntry(source) {
@Sangeetha8- To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie