- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 08:54 AM - edited 09-12-2024 09:00 AM
Hi folks,
I have the following script that sets the assignment group of catalog tasks when the request is submitted:
//Add the request and request item fields
current.short_description = "New " + current.variable_pool.device_type + " creation request";
current.due_date = current.variable_pool.date_due;
current.assignment_group = 'd4024b97db9ba600abebdee5ce96193c';
var ritmId = current.getUniqueValue();
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request); // find the REQ record
req.query();
// if REQ record found then set value
if (req.next()){
req.assignment_group = 'd4024b97db9ba600abebdee5ce96193c';
req.description = "Please complete the buildout and configuration of the " + current.variable_pool.device_type + " device requested in the attached RITM.";
req.special_instructions = specs;
req.update();
}
// Add tasks to the request item
for (var i = 0; i < tasks.length; i++) {
var taskGr = new GlideRecord('sc_task');
taskGr.initialize();
taskGr.assignment_group = 'd4024b97db9ba600abebdee5ce96193c'; //ASSIGNMENT GROUP NOT BEING SET PROPERLY (NEEDS WORK)
taskGr.short_description = tasks[i];
taskGr.parent = ritmId; // Link task to the request
taskGr.request_item = ritmId; // Link task to the request
taskGr.insert();
}
I discovered that the assignment group was being set to a different group than the one specified in my script and I identified a business rule that is setting this on insert/update (looks like it is setting a default group when the assignment group field is empty):
(function executeRule(current, previous /*null when async*/) {
//Read location of request
var loc = current.location;
if(!loc){
loc = current.variable_pool.location;
current.location = loc;
}
gs.info("LOCATION " + loc);
//Query many to many table for IT groups matching the location
var gr = new GlideRecord("u_m2m_groups_locations");
gr.addQuery("u_location", "=", loc);
gr.addQuery("u_type", "=", "IT");
gr.query();
//Check if we got a result
if(gr.next()){
//Assign groups properly
current.assignment_group = gr.u_group.sys_id;
}
//No results found
else{
//Set default assignment group on line below
current.assignment_group = "c4210317db9ba600abebdee5ce961907";//Helpdesk-Corporate
}
var req = current.request.getRefRecord();
req.assignment_group = current.assignment_group;
req.location = loc;
req.short_description = current.short_description;
//req.update();
})(current, previous);
I tried to set the BR to run after insert/update but that breaks the function of the rule and it no longer works as originally intended.
How can I get the rule to work as intended while allowing the assignment group to be set through my script?
Thanks in advance.
Ken
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 09:28 AM - edited 09-12-2024 09:29 AM
Hi Ken,
It seems like this other BR should not be running because before insert the AG is not empty, but if you're sure it is the culprit then that could be explained as timing issue. One thing you can do on your script is add this line before the taskGr.insert();
taskGr.setWorkflow(false);
This will prevent any Business Rules from running when the record is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 09:28 AM - edited 09-12-2024 09:29 AM
Hi Ken,
It seems like this other BR should not be running because before insert the AG is not empty, but if you're sure it is the culprit then that could be explained as timing issue. One thing you can do on your script is add this line before the taskGr.insert();
taskGr.setWorkflow(false);
This will prevent any Business Rules from running when the record is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 10:07 AM
Hi Brad,
I agree but am hesitant to deactivate the rule as I did not add it and want to avoid any undesired results. If I understand, this rule will always run.
I did add that line and it fixed my issue.
Thank you!
Ken