Adhoc approval "Add an Approval" Ui action not working in HR agent Workspace Tokyo

Himanshu Raj
Tera Expert

Hi All

 

I have a requirement where i am using Adhoc approval option in HR case management. I added "Agent can add an approval" in case options on HR Service. 

Add adhoc approvers to an HR case in the Agent Workspace for HR Case Management (servicenow.com)

HimanshuRaj_0-1669361933163.png

 

We have corresponding Ui action "Add an approval" I selected 'Workspace Form Button' option

HimanshuRaj_1-1669362087008.png

 

The Ui action is available on HR Agent Workspace, but it is not working. No dialog box opens in Agent workspace to add an approval although it is working fine in native UI Form view.

HimanshuRaj_2-1669362222231.png

 

If anyone have idea, please help. 

Thanks in Advance.

1 ACCEPTED SOLUTION

@Himanshu Raj 

The following code I have added in the workflow client script. Also, I have created one script Include for this.

Workspace client script:

function onClick(g_form) {

var gajax = new GlideAjax("sn_hr_core.hr_ApprovalUtilsAjax");
gajax.addParam("sysparm_name", "isAdhocApprovers");
gajax.addParam("sysparm_sys_id", g_form.getUniqueValue());
gajax.addParam("sysparm_parent_table", g_form.getTableName());
gajax.getXMLAnswer(launchAdhocApprovalDialog);


function launchAdhocApprovalDialog(response) {

if (!response || response == 'false') {
g_form.addErrorMessage(getMessage('Adhoc approval action can not be performed'));
return;
} else {
var fields = [{
type: 'glide_list',
name: 'approver_users',
label: getMessage('Approver users'),
referringTable: 'sn_hr_core_service_activity',
referringRecordId: '-1',
dictionary: {
reference: 'sys_user'
},
mandatory: true,
},
{
type: 'choice',
name: 'wait_for',
value: 'anyone',
label: 'Wait For',
choices: [{
displayValue: 'Anyone to approve',
value: 'anyone'
},
{
displayValue: 'Everyone to approve',
value: 'everyone',
},
{
displayValue: 'First responce from aynyone',
value: 'first_response',
},
],
},
{
type: 'choice',
name: 'on_rejection',
value: 'resubmit',
label: 'On rejection',
choices: [{
displayValue: 'Allow resubmit of approvals',
value: 'resubmit'
},
{
displayValue: 'Closed incomplete',
value: 'close_case',
},
],
},
{
type: 'choice',
name: 'ac_or_wk',
value: '1',
label: 'Select work notes or additional comments',
choices: [{
displayValue: 'Additional comment',
value: '2'
},
{
displayValue: 'Work note',
value: '1'
},
],
},
{
type: 'textarea',
label: 'Reason',
name: 'reason,'
},
]
g_modal.showFields({
title: "Add an approval",
instruction: 'After filling out these details and sending for approval, an approval process will be added to this request.',
confirmTitle: "Send for Approval",
fields: fields,
size : 'lg',
}).then(function(fieldValues) {
var gr = new GlideAjax('sn_hr_core.add_an_approval');
gr.addParam('sysparm_name', 'sendApproval');
gr.addParam('sysparm_approvers', fieldValues.updatedFields[0].value);
gr.addParam('sysparm_waitFor', fieldValues.updatedFields[1].value);
gr.addParam('sysparm_onRejection', fieldValues.updatedFields[2].value);
gr.addParam('sysparm_tableName', g_form.getTableName());
gr.addParam('sysparm_sys_id', g_form.getUniqueValue());
gr.addParam('sysparm_comment', fieldValues.updatedFields[3].value);
gr.addParam('sysparm_reason', fieldValues.updatedFields[4].value);
gr.getXML();
g_form.save();
});

}
}


}

 

Script Include :

var add_an_approval = Class.create();
add_an_approval.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

sendApproval: function() {
var usersStr = this.getParameter('sysparm_approvers');
var selectedWaitFor = this.getParameter('sysparm_waitFor');
var selectedOnReject = this.getParameter('sysparm_onRejection');
var tableName = this.getParameter('sysparm_tableName');
var task_sys_id = this.getParameter('sysparm_sys_id');
var comment = this.getParameter('sysparm_comment');
var reason = this.getParameter('sysparm_reason');
var caseGr = new GlideRecord(tableName);

if (!usersStr || !caseGr.get(task_sys_id))
return;

if (comment == 1) {
caseGr.work_notes = 'Adhoc approval reason:' + reason;
}
if (comment == 2) {
caseGr.comments = 'Adhoc approval reason:' + reason;
}

var vars = {};
vars.adhoc_approvers = usersStr;
vars.wait_for = selectedWaitFor;
vars.on_rejection = selectedOnReject;

sn_hr_core.hr_ApprovalUtil.startAdhocApprovalFlow(caseGr, vars);
caseGr.update();

var str = tableName + ".do?sysparm_query=sys_id=" + task_sys_id;
response.sendRedirect(str);
},

type: 'add_an_approval'
});

 

Please let me know if it is helpful for you or not.

Thank You!

 

View solution in original post

7 REPLIES 7

Pratiksha_45
Kilo Sage

Hello Himanshu,

I am also facing this issue. Have you got any solution for this?

@Pratiksha_45 Not yet, it seems Hi ticket need to be created. Please update here if you find anything regarding this. 

Thanks

Himanshu Raj

Hello @Himanshu Raj ,

I have solved this issue in my Instance. I have written the script in the Workspace client script of UI action.

Thanks!

 

@Pratiksha_45 This should have been working fine OOB right? Will you please let me know what code you added in Workspace client script of UI action to make it work.