- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 01:07 PM
I have this transform map that updates or inserts records into the incident table coalescing off an id field. Unfortunately, sometimes the col_id value passed in matches an incident where the state is closed. If the state is closed I want it create/insert a new incident and not re-open it and update it.
So I'm trying to get an onBefore script to work but it doesn't seem to want to work. Any ideas on how to make this happen?
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grIncident = new GlideRecord('incident');
grIncident.addQuery('correlation_id', source.correlation_id); //correlation_id
grIncident.addQuery('state', '!=', 7);
grIncident.query();
//matching incident record found. will update
if (grIncident.next()){
}
else {
//no matching record found or if found was closed. create/insert new record
action = "insert";
}
})(source, map, log, target);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 01:13 PM
You can do some improvements to the script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if (target.active!=true && action == "update")
action = "insert";
})(source, map, log, target);
If this doesnt work, you will have to use ignore to ignore the current update and then insert the record using script for ex
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if (target.active!=true && action == "update")
{
ignore = "true";
var gr = new GlideRecord('incident');
gr.initialize();
gr.correlation_id = source.correlation_id;
// Add additional fields here
gr.insert();
}
})(source, map, log, target);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 08:05 AM
Thanks for the suggestion but like from my original script it still will update and reopen a closed matching incident. 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 08:19 AM
No it will not update if you mention action =insert. It will only insert a record. Kindly check once.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 08:20 AM
Alternatively, you can do it like this. Add ignore=true so that the record is skipped and then insert a record from script.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grIncident = new GlideRecord('incident');
grIncident.addQuery('correlation_id', source.correlation_id); //correlation_id
grIncident.addQuery('state',7);
grIncident.query();
//matching incident record found. set action to insert to create new record
if (grIncident.next()){
ignore=true;
grIncident.initialize();
//ADD YOUR FIELDS HERE
grIncident.insert();
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 08:06 AM
1) Can you try some thing like this:
onBefoe Script:
if(action== "update"){
if(source.active == true){
action = "insert";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 08:26 AM
I wish this would have worked as its much more compact but I never could get it to work when using action = 'insert'. thanks