Update field while Standard Change is created in flow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
Currently, we cannot find an option to update the fields of a Standard Change request in the workflow action 'Create Change Request'.
The Standard Change workflow includes an approval stage which queries the assigned_to users manager, however, we cannot find a way to populate the assigned_to field before the Standard Change template is created (in new flow) and the CHG's workflow skips the manager approval since no user is assigned to the CHG.
The assignment field is mandatory, but without being able to set the assigned_to field before creation, the workflow has no way of assigning approval. Is there anyway to update the standard change record as it is being created within the flow? (preferably without editing the Standard CHG Template itself)
- Labels:
-
Workflow Data Fabric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
After reviewing with a ServiceNow Rep, this is achieved through a custom flow action. Inputs and outputs are listed in the code... Our team was able to configure this successfully. The script below is a generalized action script and can be configured to any group.
We needed this since you cannot assign a user to a standard CHG while creation in flow designer(unlike a normal CHG creation) - which would throw the standard CHGs approval flow out of whack. In this script, the user is assigned during creation. We linked this assignment to the flows previous Task - our flow waits until this task is assigned before the custom action is ran, and Std-CHG is created.
(function execute(inputs, outputs) {
// Get the info we need from your flow
var templateSysId = inputs.template_sys_id;
var assignedToUser = inputs.assigned_to_user;
var requestItemSysId = inputs.ritm_sys_id;
// Grab the template data
var templateGR = new GlideRecord('std_change_producer_version');
if (templateGR.get(templateSysId)) {
// Create the new Change Request
var changeGR = new GlideRecord('change_request');
changeGR.initialize();
// Copy over all the template stuff
changeGR.setValue('type', 'standard');
changeGR.setValue('std_change_producer_version', templateSysId);
changeGR.setValue('short_description', templateGR.getValue('short_description'));
changeGR.setValue('description', templateGR.getValue('description'));
changeGR.setValue('category', templateGR.getValue('category'));
changeGR.setValue('subcategory', templateGR.getValue('subcategory'));
changeGR.setValue('priority', templateGR.getValue('priority'));
changeGR.setValue('risk', templateGR.getValue('risk'));
changeGR.setValue('impact', templateGR.getValue('impact'));
//Assign the user BEFORE we create the record!
changeGR.setValue('assigned_to', assignedToUser);
// Link it back to your original request
changeGR.setValue('requested_by_task', requestItemSysId);
// Get the requesting user from the RITM
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(requestItemSysId)) {
changeGR.setValue('requested_by', ritmGR.getValue('requested_for'));
}
// Now create the record with everything set up properly
var changeSysId = changeGR.insert();
// Send back the info your flow needs
outputs.change_request_sys_id = changeSysId;
outputs.change_request_number = changeGR.getDisplayValue('number');
outputs.success = true;
} else {
gs.error('Oops! Could not find that template: ' + templateSysId);
outputs.success = false;
outputs.error_message = 'Template not found';
}
})(inputs, outputs);