- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 03:34 AM
I want to load data via email attachment, and create an incident at the same time while loading data, but how to associate the new incident record with loaded data? Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 09:31 PM
Hi,
can you print what came in source.sys_import_set.number?
try this
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gr = new GlideRecord("incident");
gr.initialize();
gr.short_description = import_set.number;
gr.insert();
})(source, map, log, target);
Similarly update the onAfter
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gr = new GlideRecord("incident");
gr.addQuery("short_description", "LIKE", import_set.number);
gr.query();
if (gr.next()) {
target.fieldName = gr.getUniqueValue(); // if target field is reference to incident
// OR
// target.fieldName = gr.number; // if target field is string
}
})(source, map, log, target);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 03:54 AM
Please mark my response as correct and close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 12:56 AM
Thank you ! I got you, but I have a issue, once use this script , when load data next time ,you have to change the After script, If dont change ,the incident number still last incident number,but it isn't what I want. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 02:52 AM
Hi,
to make it dynamic you can do this
1) use onStart transform script and in that create the incident
2) include the import set number in short_description of the incident
3) then when you query you can search with that import set number
onStart:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gr = new GlideRecord("incident");
gr.initialize();
gr.short_description = source.sys_import_set.number;
gr.insert();
})(source, map, log, target);
onAfter:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gr = new GlideRecord("incident");
gr.addQuery("short_description", "LIKE", source.sys_import_set.number);
gr.query();
if (gr.next()) {
target.fieldName = gr.getUniqueValue(); // if target field is reference to incident
// OR
// target.fieldName = gr.number; // if target field is string
}
})(source, map, log, target);
I hope I have answered your question.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 06:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 07:38 PM
Hi,
where did you write the script for incident creation?
What debugging you performed?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 08:38 PM