UI Action for Request Approval button for change

Suresh_32
Tera Expert

Hi All,

 

'Request Approval' button is not working if change type is Retro or Emergency.

'Request Approval' button is working if change type is Normal.

 

The existing code for is shown below. When you update the 'Approval Group' field in the change form without saving it, the 'Request Approval' button should not be submitted and a pop-up message should appear.

 

The 'Approval Group' field appears only in the 'Normal' change form , but not appears in the 'Retro and Emergency' change forms.

 

Please correct the following code for Retro and Emergency changes also.

 

Please assist me on this issue

 

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)

 

UI 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());
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');

} 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();
}

 

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'
});

5 REPLIES 5

Sebas Di Loreto
Kilo Sage
Kilo Sage

Hi @Suresh_32 

Since your issue is with the display with the "Request Approval" button (ui action), then focus on the condition for that UI action and think how it is applied on different change types:

  • current.isValidRecord() && current.state == '10':  I don't think there is any issue here since this button will show for all change types on state 10.
  • && new HideRequestApproval().groupHasNoMembers(current.u_approval_group) && new HideRequestApproval().groupHasInActiveMembers(current.u_approval_group):  most likely this is where the issue is since all conditions are tied together with AND operators, so let's focus here.

The two lines call different functions within the "HideRequestApproval" script include (not out of the box).

The two functions are looking if the group you provided, u_approval_group field on the change, has "no members" or "has active members". Anyway, the functions are irrelevant in this analysis since everything focus on the u_approval_group field, which is not out of the box and most likely was created on the change_request table.

In addition, according to what you already explained, this field is displayed on the NORMAL change form but it is hidden on the Retro or Emergency types. Then for Retro or Emergency changes, you are not able to insert information in the u_approval_group field and most likely those functions evaluate to FALSE. That is what makes the "request approval" button not to display for Retro or Emergency changes.

There must be a UI policy (it could be a script include) hiding the u_approval_group field for Retro or Emergency changes. You can try deactivating that UI policy and testing it.

In addition, you could remove the script include and functions from the "request approval" button (UI action) condition, leaving just with: current.isValidRecord() && current.state == '10' BUT I don't think it will render what you want since the u_approval_group field (still hidden) will be empty for the Retro or Emergency changes.

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.