Make"Rejection" comments mandatory while rejecting a Change via List Context menu UI Action i.e. Right Click Reject option in Change Approvers related list.

sarthak92
Giga Expert

There is a requirement to make the "comments" mandatory if someone rejects the Change Ticket via the list context menu UI Action i.e. right click on the Approver related list. I managed to make some modifications in the script posted in the community by someone else with similar requirement but its not working as expected. Although, after clicking Reject, its redirecting to enter the mandatory comments but after entering the comments, state is not changing to "Rejected". Can anyone help on this ?

function rejectRequest()

{
if (g_form.getValue('comments') == '')

{
//Remove any existing field message, set comments mandatory, and show a new field message

try {g_form.hideFieldMsg('comments');} catch(e) {}

g_form.showFieldMsg('comments','Please provide comments for rejection.','error');

return false; //Abort submission

}

//Call the UI Action and skip the 'onclick' function

gsftSubmit(null, g_form.getFormElement(),'Reject'); //MUST call the 'Action name' set in this UI Action

}

if (typeof window == 'undefined')

serverReject();

function serverReject()

{

current.state='rejected';

current.update();

}

Note : function rejectRequest(); is in 'Onclick' field of the ui action form.

1 ACCEPTED SOLUTION

scott barnard1
Kilo Sage

I use this as a ui action on the approval table with appropriate conditions

 

current.state = 'rejected';

if (!gs.nil(current.comments))
current.update();
else {
gs.addErrorMessage(gs.getMessage("Comments are required when rejecting an approval"));
current.state = 'requested';
current.setAbortAction(true);
action.setRedirectURL(current);
}

 

Bear in mind what you want your state to be if they don't add the comment.

View solution in original post

19 REPLIES 19

saiiaskumar
Mega Guru

List Context menu button on approval table

Ui Action : 

Name : Reject context menu

Action Name : rejection_comments_ui_context

List Context Menu : True

OnClick : loadDialog();

Condition : current.state == 'requested'

Script : 

var rejectionComments,gr,selectdIds;


function loadDialog(){


try{


var tableName = g_list.getTableName();
var GlideList = GlideList2 ? GlideList2 : GlideList;
selectdIds = g_list.getChecked();


if(!selectdIds){


alert("Please select the record checkbox in list view");
return;


}


gr = new GlideRecord(tableName);
gr.get(selectdIds);


if(gr.comments == "")
alert("Comments mandatory");


rejectionComments = new GlideModal("rejection_comment_approval", false, 648, 250);
rejectionComments.setTitle(new GwtMessage().getMessage("Enter Rejection Comments"));
rejectionComments.render();


}catch(e){


alert("error1 is : "+e);


}
}


function moveToReject(notes){


try{


gr.setValue("comments",notes);
gr.setValue("state","rejected");
gr.update();
rejectionComments.destroy();
document.location.reload();


}catch(e){


alert("error is : "+e);


}
}

 

The above ui action will call Dialog Window.

Ui Page : 

Name : rejection_comment_approval

HTML Code in UI Page: 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<g:dialog_notes_ok_cancel
dialog_id="rejection_comment_approval"
textarea_id="my_approval_rejection_reason"
textarea_label="${gs.getMessage('Rejection Reason')}"
textarea_label_title="${gs.getMessage('Comments are required to reject the approval')}"
textarea_name="my_approval_rejection_reason"
textarea_onkeyup="enableButton()"
textarea_onchange="enableButton()"
textarea_style="height:auto; width: 100%; resize: vertical;"
textarea_title="${gs.getMessage('Enter Comments here')}"
ok=""
ok_action="rejectTheRequest"
ok_id="approval_reject_ok_btn"
ok_title="${gs.getMessage('Rejected the Approval')}"
ok_type="button"
ok_style_class="btn btn-primary disabled"
cancel_title="${gs.getMessage('Close the dialog')}"
/>
</j:jelly>

 

Client Script in UI Page : 

function rejectTheRequest() {


var textArea = $("my_approval_rejection_reason");
if (textArea)
{
moveToReject(textArea.value.trim());
}


}
(function() {
$("my_approval_rejection_reason").focus();
})();

 

Try with above UI Action and UI Page code.

dinesh86
Kilo Explorer

Can you pls tell me how you achieved the above requirement.

dinesh86
Kilo Explorer

@sarthak92  Please help me achieve the above requirement.

G_30
Tera Contributor

Hi,

 

did you able to resolved this issue?

I tried to work on the script solution but it does not allow the user to reject in list even if there's already comment on the approver's table,

 

thanks!

klavan32
Tera Contributor

Hi, we have configuration where comments are mandatory while rejecting the approval record, so need to provide comments while clicking on button. Here the problem is, it is making the state changed first then posting the comments. this behavior is preventing the notification to miss the comments posted. 

Please help on how to make comments posted first then make the state changed?