- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 12:35 PM
Hello I have a catalog item that is suppose to update a Incident after submission but I seem to be having problems with the script. The idea is that on the catalog item you select the incident you wish to update, the values like the current inc short description are populated.
When you submit whatever changes you made should then update the incident referenced in the field. I am doing this via a business rule but seem to be having some trouble here is my code.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("incident");
gr.addQuery('number', current.variable_pool.incident);
gr.query();
while (gr.Next()){
gr.caller = current.variable_pool.caller;
gr.short_description = current.variable_pool.short_description;
gr.description = current.variable_pool.description;
}
})(current, previous);
I should note the business rule triggers "after" insert of the catalog item.
Any assistance would be helpful thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2022 06:56 AM
Thank you all for your help it seems like the issue was a combination on what you all mentioned.
1. I had accidently made "Next()" capitalized.
2. I forgot the gr.update()
3. the variable for incident was mapped to sys id so I dot walked to incident.number.
4. Changing to a before business rule helped also.
Thank you for your assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 02:21 PM
Hey Dagarson,
1.)What table is your business rule running on?
2.) are you wanting to submit another ticket or just update the incident you select?
3.) is this submitting a record producer on the incident table or a catalog task?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 02:26 PM
1. The BR is running on the sc_req_item table.
2. No I want it to update the existing incident based on the changes selected on the catalog item.
3. Neither. It should update the existing Incident when the catalog item is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 02:45 PM
try below. I added some log statements to see what values you are getting.
if you're not wanting another record submitted for this switch to a before insert business rule.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("incident");
gr.addQuery('sys_id', current.variables.incident);
gs.info('SYS_ID: ' + current.variables.incident);
gr.query();
if (gr.next()){
gr.caller = current.variables.caller;
gs.info ('CALLER: ' + current.variables.caller)
gr.short_description = current.variables.short_description;
gs.info ('SHORT DESC: ' + current.variables.short_description)
gr.description = current.variables.description;
gs.info ('DESC: ' + current.variables.description)
gr.update();
current.setAbortAction(true);
}
})(current, previous);
please mark helpful or correct 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 07:21 PM
Hi
if Your variables are in Variable Set
// if Your variables are in Variable Set
var vsn = current.variables.<variableSetName>.<variableName>;
//Example:
//Variable Set Name = user_details; // VariableSet Value
//Variable Name = caller;
var vsn = current.variables.user_details.caller;
If You have variables
//You have variables
var vn = current.variables.<variableName>;
//Example:
//Variable Name = caller;
var vn = current.variables.caller;
Please Check
Shakeel Shaik 🙂