UI Action that creates a group approval for a Task based record

psnow123
Giga Guru

I'm trying to create a UI Action script for a button that says 'Send for Approval' on an 'Assessment' entity that I extended from Task.

 

The button on the form needs to create a group approval, and when the members (there are more than one member) approves, then the 'Assessment' will show as status 'Approved'.

 

I've been able to create the Group approval, and the Approval request shows in the service portal for the users, but when you approve the request, the 'Assessment' record state is still Not Yet Requested.  

 

What's the best approach to ensure the 'Assessment' record is updated once the approvals are given?  A flow that monitors the the sysapprover_approver table (which has individual request records per user) for changes to 'Assessment' requests for approval and then update the 'Assessment' Approval field?

 

Basically, how can you use code to manage the approval status of a Task extended entity, using Group Approvals?  It seems to just 'work' using Send for Approvals in Flow designer...

 

 

var approvalTable = "sysapproval_group"; // Name of the group approval table
var approvalRec = new GlideRecord(approvalTable); // Create a new GlideRecord object for the group approval table

// Set the fields for the new group approval record
approvalRec.initialize();
approvalRec.approval = 'requested'; // Set the approval status to 'requested'
approvalRec.parent = current.sys_id; // Set the parent to the current record's sys_id
approvalRec.short_description = current.short_description;
approvalRec.description = current.description;

// // Set the group and group approver fields for the new group approval record
var groupName = "approvers"; // Replace with the name of your group
var groupInfo = new GlideRecord("sys_user_group");
if (groupInfo.get("name", groupName)) {
    approvalRec.assignment_group = groupInfo.sys_id;

}
// Set the comments to include the name of the user and record ID
var userName = gs.getUserDisplayName();
var recordID = current.number;
var comments = "New group approval requested by " + userName + " for record " + recordID;
approvalRec.comments = comments;

// Insert the new group approval record into the database
approvalRec.insert();

// Display a success message to the user
gs.addInfoMessage("New group approval record created");
action.setRedirectURL(current);

 

psnow123_0-1680724973021.png

 

 

 

0 REPLIES 0