The "Request Approval" button is not working for Retro and Emergency changes

Sravani47
Tera Contributor

When click the "Request Approval" button is not working for Retro and Emergency change forms.

 

UI Action for "Request Approval":

Onclick: checkgrp();

Condition : current.isValidRecord() && current.state == '10' && new HideRequestApproval().groupHasNoMembers(current.u_approval_group) && new HideRequestApproval().groupHasInActiveMembers(current.u_approval_group)

 

Script:

// current.state = '10';
// action.setRedirectURL(current);
// current.approval = 'requested';
// current.update();

function checkgrp() {
var ajax = new GlideAjax('ValidateApprovalGroup');
ajax.addParam('sysparm_name', "getApprovalGroup");
ajax.addParam('sysparm_existingsys', g_form.getUniqueValue());
gs.addInfoMessage(gs.getMessage("Test Message123"));
ajax.getXML(getdata);

function getdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer.toString() == g_form.getValue("u_approval_group")) { //if both are same then only update else throwing the error
gsftSubmit(null, g_form.getFormElement(), 'request.approval');
gs.addInfoMessage(gs.getMessage("Test Message1234"));
} else {
alert("Before click on the 'Request Approval' button \nPlease Save the form");
}
}
}
if (typeof(window) == 'undefined')
updateAndRedirect();

function updateAndRedirect() {
current.state = '10';
action.setRedirectURL(current);
current.approval = 'requested';
current.update();
}

screen shot for UI Action - 'Request approval' button in change form

Sravani47_0-1667413252017.pngSravani47_1-1667413376576.png

 

Script Include code:

var ValidateApprovalGroup = Class.create();
ValidateApprovalGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApprovalGroup: function() {
var gr = new GlideRecord("change_request");
gr.addQuery("sys_id", this.getParameter("sysparm_existingsys"));
gr.query();
if (gr.next()) {
return gr.getValue("u_approval_group");
}
},
type: 'ValidateApprovalGroup'
});

 

Please help on this issue.

1 ACCEPTED SOLUTION

Hi @Sravani47,

 

It seems you are modifying your UI action to check some conditions in on-click function for Normal change request.

 

I would recommended you to create a new UI action that will work for Normal change request and keep existing UI action for remaining change requests with type is normal.

 

Kindly hit Kudos and mark it correct based on your impact!

 

Thanks,

Sagar Pagar

 

The world works with ServiceNow

View solution in original post

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi @Sravani47,

What should be the expected behavior, when user click Request approval button?

Is there any error or message appears?

 

Thanks,
Sagar Pagar

The world works with ServiceNow

When the user clicks the 'Request approval' button, the state field should be set to 'Awaiting Authorisation,' the approval field should be set to 'Requested,' and the 'Request approval' button should be hidden.

 

No Error or message appears.

Hi Sagar,

created New 'Request Approval' Button for Normal type,

 when click the 'request approval' button for Normal change, facing error message is

"Action not authorized" 

Please assist me on this.

 

 

Sravani47
Tera Contributor

Please assist me on this issue.