- 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:54 PM
When a Reference field type is not found, if you'd like to ignore creating a new record in the referenced table, you can set the Choice action to one of the following values:
- ignore – ignores new records in the reference field and completes processing of all other fields in the transform map.
- reject – stops the transform for the entire record.
Sample.
If you'd like to ignore any new insert in your transform map, you can use the following script:
(function transformRow(source, target, map, log, isUpdate) {
if (action == 'insert') {
ignore = true;
}
})(source, target, map, log, action === "update");
Cheers,
Tai Vu