Button not working in assessment workspace

mekalaprasa
Tera Contributor

I have created a button in the assessment workspace, for assessment template page but unable to execute approval request using this button tried to configure event and also tried to do it using data resource but not sure what's going wrong.

 

sharing the info of what I have tried here 

 

mekalaprasa_0-1753422800998.png

tried using data resource scriptlet

mekalaprasa_1-1753422945780.png

 

 script used for it 

/**
 * @Param {string} templateId - sys_id of the Smart Assessment Template
 * @Param {string} groupId - sys_id of the approval group
 */
(function(inputs, outputs) {
    var templateId = inputs.templateId;
    var groupId = inputs.groupId;

    if (!templateId || !groupId) {
        outputs.success = false;
        outputs.message = "Missing templateId or groupId.";
        return;
    }

    var existing = new GlideRecord('sysapproval_approver');
    existing.addQuery('document_id', templateId);
    existing.addQuery('source_table', 'sn_smart_asmt_template');
    existing.addQuery('group', groupId);
    existing.addQuery('state', 'requested');
    existing.query();

    if (existing.hasNext()) {
        outputs.success = false;
        outputs.message = "Approval already exists.";
        return;
    }

    var approval = new GlideRecord('sysapproval_approver');
    approval.initialize();
    approval.document_id = templateId;
    approval.source_table = 'sn_smart_asmt_template';
    approval.group = groupId;
    approval.state = 'requested';
    approval.insert();

    outputs.success = true;
    outputs.message = " Approval created successfully.";
})(inputs, outputs);
 
Added data source to the event
 
mekalaprasa_2-1753423068969.png

Please help resolve this issue, or help me with alternative approach of creating an approval request in the table 'sysapproval_approver'

 

thanks, in advance🙏

3 REPLIES 3

GlideFather
Tera Patron

Hi @mekalaprasa 

could you please attach the pictures by that clip icon? Not your fault but we cannot read them

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hi @GlideFather , I have added the screenshots below.

 

Thanks in advance.

Ayush Aggarwal
ServiceNow Employee
ServiceNow Employee

Hi @mekalaprasa ,

Can you please share the screenshot of configured event handler for the button, data broker which calls the transform script as well as client script which is called by the button which executes the data broker?