- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 12:08 PM
Hello all,
I'm very new to scripting, but I'm trying to put together the following:
Expectation:
If a user is in a group called MXUsers and they submit an INC, it should be closed and a REQ should be created and trigger the workflow for a specific catalog item.
Current Status:
The INC gets closed with all the fields I've defined in the script. The REQ gets created with the correct RITM.
Roadblock:
The workflow does not trigger. The RITM should be approved by one of our internal IT groups and create a Task.
I have validated the workflow and tested straight from the Service Catalog which works as expected. Below is the script I'm using:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//If the user is in the MXUsers group, this script should run
var incidentCallerID = current.caller_id;
var specificGroup = 'MXUsers';
var groupMember = false;
var userGR = new GlideUser();
userGR.get(incidentCallerID);
var userGroups = userGR.getMyGroups();
while (userGroups.next()) {
if (userGroups.name == specificGroup) {
groupMember = true;
break;
}
}
//Create REQ
var requestGR = new GlideRecord('sc_request');
requestGR.initialize();
requestGR.requested_for = current.caller_id;
requestGR.short_description = current.short_description;
var requestSysID = requestGR.insert();
//Create RITM
var requestItemGR = new GlideRecord('sc_req_item');
requestItemGR.initialize();
requestItemGR.request = requestSysID;
requestItemGR.cat_item = '0ef92e0d1b3f91105bc24002dd4bcb7b';
requestItemGR.short_description = current.short_description;
requestItemGR.insertWithReferences();
// var ritmSysID = requestItemGR.insert(); This was line 33 at first //
//Set fields on INC
current.state = 7;
current.assigned_to = '60fc7e111b1745505bc24002dd4bcbd5'; //Assign to Glenn
current.assignment_group = '46f9f7c41bb1e090e0f5eac9bc4bcbeb'; //Assign to Helpdesk
current.close_code = 'Not Solved (Raised Request)';
current.u_category = 'Inquiry / Help';
current.u_subcategory = 'Ticket Routing';
//Get new RITM number to show in Resolution Notes
var ritmNumber = '';
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('request', requestSysID);
ritmGR.query();
if (ritmGR.next()) {
ritmNumber = ritmGR.number;
}
var closeNotes = 'Raised Request - ' + ritmNumber;
current.close_notes = closeNotes;
current.update();
}
)(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 07:39 AM
Replace the part of your code //Create REQ and //Create RITM by Cart code and if you want to change the short description of your RITM you need to query .
it can be something like this :
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//If the user is in the MXUsers group, this script should run
var incidentCallerID = current.caller_id;
var specificGroup = 'MXUsers';
var groupMember = false;
var userGR = new GlideUser();
userGR.get(incidentCallerID);
var userGroups = userGR.getMyGroups();
while (userGroups.next()) {
if (userGroups.name == specificGroup) {
groupMember = true;
break;
}
}
//Create your Request
}
//Set fields on INC
current.state = 7;
current.assigned_to = '60fc7e111b1745505bc24002dd4bcbd5'; //Assign to Glenn
current.assignment_group = '46f9f7c41bb1e090e0f5eac9bc4bcbeb'; //Assign to Helpdesk
current.close_code = 'Not Solved (Raised Request)';
current.u_category = 'Inquiry / Help';
current.u_subcategory = 'Ticket Routing';
var closeNotes = 'Raised Request - ' + ritm.number;
current.close_notes = closeNotes;
current.update();
}
)(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:43 AM
Hi OthArk,
One more question. Everything works as expected, including the Short Description being copied to the RITM. I just need the body of the email to copy over to the Description field. I've tried many ways to do this. What would you recommend?