The CreatorCon Call for Content is officially open! Get started here.

Setting Approver in Workflow Editor Using Scratchpad

appstorm
Tera Contributor

When trying to set an Approver from scratchpad in Workflow Editor, I can successfully store and assign the sys_id of the Instructor from the student_information field on our form, but it does not set the Instructor as Approver in the approver - user action.  Instead, it leaves the approver field empty and passes to the next step in the workflow.

 

// Access the course_information reference field (from the RITM or appropriate record)
var courseInfo = current.variables.course_information;  // Adjust according to where the course reference is

// Check if course_information is valid
if (courseInfo) {
    // Query the sn_uni_req_larf_banner_courses table using course_information (the reference field)
    var gr = new GlideRecord('sn_uni_req_larf_banner_courses');
    if (gr.get(courseInfo)) {  // Get the record from the sn_uni_req_larf_banner_courses table
        // Log to verify we have found the record
        gs.info('Found sn_uni_req_larf_banner_courses record for course code: ' + gr.u_course_code);

        // Access the u_instructor_name field directly from the sn_uni_req_larf_banner_courses record (this is expected to be sys_id)
        var instructorSysId = gr.u_instructor_name;  // Ensure this is a sys_id (reference to sys_user)

        // Log the instructor's sys_id
        gs.info('Instructor sys_id: ' + instructorSysId);

        // Store the instructor's sys_id in the scratchpad to be used in other steps (like approval)
        workflow.scratchpad.instructorName = instructorSysId;
        gs.info('Instructor sys_id stored in scratchpad: ' + workflow.scratchpad.instructorName);

        // Now, set the approver to the instructor sys_id
        current.approver = instructorSysId;
        gs.info('Instructor sys_id assigned as approver: ' + instructorSysId);
    } else {
        // Log if the sn_uni_req_larf_banner_courses record was not found
        gs.info('No matching sn_uni_req_larf_banner_courses record found for course information.');
        workflow.scratchpad.instructorName = '';  // Ensure scratchpad is empty if no instructor is found
        current.approver = '';  // Ensure approver is cleared if no instructor is found
    }
} else {
    // Log if course_information is not set or valid
    gs.info('course_information is not set or valid.');
    workflow.scratchpad.instructorName = '';  // Ensure scratchpad is empty if no course information
    current.approver = '';  // Ensure approver is cleared if no course information
}

 

Screenshot 2025-03-25 at 12.12.40 PM.png

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

The Approval - User activity must push one or more sys_ids from the sys_user table to an array with the name 'answer'.  You can use the scratchpad variable for this assignment, or the 'Approver' field on the RITM if you have created such a field, or an 'Approver' variable on a Catalog Item.  Using scratchpad would look like this:

var answer = workflow.scratchpad.instructorName;