Transfer a record and then set approval state to requested.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 07:07 AM
Hi Everyone,
I am working on a use case for a scoped app.
I have two Business Types.
If a business type is submitted, then it is determined by the fulfillment team a transfer is is required that also will need approval after the transfer. Is there a way to set the approval state on the record to requested?
I have tried to create a script that says if the record is transferred set the approval state to requested but it does not work.
See below.
// JavaScript function to update approval state to "requested"
function updateApprovalStateToRequested() {
var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the actual table name
gr.get(current.sys_id); // 'current' is a reference to the current record being processed
if (gr.isValid()) {
gr.approval_state = 'requested'; // Assuming 'approval_state' is the field representing the approval state
gr.update();
}
}
// Create a UI Policy Action
var Set Approval State = new GlideUIPolicyAction();
setApprovalState.setTable('my_table_name');
setApprovalState.setCondition('Transferred'); // Define conditions when this UI Policy should be applied
setApprovalState.setActionName('Set Approval State to Requested');
setApprovalState.setScript(updateApprovalStateToRequested);
setApprovalState.insert();
If anyone can provide assistance I would appreciate the assist.