- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:09 PM
I wrote a before transform map event script. but it still not working .
can anyone please help me on this . and please verify what are the error in this script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:27 PM - edited 01-04-2024 08:38 PM
@Jyoti Ranjan Se : Try with the below script by replacing it with your field name.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if (action == 'insert' && JSUtil.notNil(source.your_field_name)) {
var gr = new GlideRecord('sys_user');
gr.addQuery('first_name', source.your_field_name);
gr.query();
if (!gr.next()) {
ignore = true;
}
}
})(source, map, log, target);
2. This also can be done with field mapping, with choice action.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:50 PM
your Reference variable is not defined and script won't know what it contains
please add this line
var Reference = source.u_fieldName; // give here the field name
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:20 PM
Hi @Jyoti Ranjan Se ,
Why are you writing an onBefore script. U can simply use field map for this n make it as coalesce true.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:27 PM - edited 01-04-2024 08:38 PM
@Jyoti Ranjan Se : Try with the below script by replacing it with your field name.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if (action == 'insert' && JSUtil.notNil(source.your_field_name)) {
var gr = new GlideRecord('sys_user');
gr.addQuery('first_name', source.your_field_name);
gr.query();
if (!gr.next()) {
ignore = true;
}
}
})(source, map, log, target);
2. This also can be done with field mapping, with choice action.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:07 PM - edited 01-04-2024 10:19 PM
if i want to validate 5 reference filed two have them are not present in source data then how can i write one script for all of them??
please help me.
Thanks
jyoti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:50 PM
your Reference variable is not defined and script won't know what it contains
please add this line
var Reference = source.u_fieldName; // give here the field name
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader