Approval button for individual outstanding tasks

Community Alums
Not applicable

Hi All

I have a requirement to add an Approval button to a form. The button should only be visible if the user has an outstanding approval task on that form. 

I'm fairly new to scripting. I've done UI Action approval buttons before, but they were done with a condition to say when to show it, and it would move the whole ticket along. In this scenario i just want the approval button to approve the approval task of the user who clicks approves. 

I'm kinda of lost. Do i need a business rule, a script include?? 

any suggestions would be greatly appreciated. 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

So I ended up doing a UI Page for a pop up to capture comments on the approval or reject buttons. 

The UI Action script simply calls the UI Page which has the meat of the script in it. 

UI Action:

function onClickApprove(){
	var dialog = new GlideDialogWindow("approvalComments");
	dialog.setTitle('Please enter comments to approve this procurement');
	dialog.setSize(450,550); //Set the dialog size
	dialog.removeCloseDecoration(); //remove the close cross from the dialogwindow
	dialog.render();
}		

The UI Page script:

function updateApproval(action) {
	var textArea = gel('approval_comments'); //Pass the comment from the user
	textArea = textArea.value.trim();
	var sys_id = g_form.getUniqueValue(); // Get the sys_id of the procurement
	var approvaRec = new GlideRecord('sysapproval_approver'); //Approval table
	approvaRec.addQuery('document_id', sys_id);
	approvaRec.addQuery('approver', g_user.userID); // Get the current user ID
	approvaRec.addQuery('state', 'requested');
	approvaRec.query();
	if (approvaRec.next()) {
		approvaRec.state = 'approved'; //
		approvaRec.comments = textArea; // Get the value from the gel object and trim.
		approvaRec.update();
		if ((g_form.getValue('** FIELD NAME OF STAGE WE WANTED TO CHECK **') == '** THE VALUE OF THE FIELD ** ' ) || (g_form.getValue('**ANOTHER FIELD NAME**') == '**VALUE OF FIELD**')) {
			g_form.setValue('u_neg_directive', textArea); 
		g_form.save();  }
		
				gsftSubmit(null, g_form.getFormElement(), "sysverb_update_and_stay"); //Save and Stay
		}
		
	}


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

The UI Page HTML looks like this: 

<?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="change_confirm_cancel"
		textarea_id="approval_comments"
		textarea_label="${gs.getMessage('')}"
		textarea_label_title="${gs.getMessage('Approval comments are required')}"
		textarea_name="approval_comments"
		textarea_onkeyup="enableButton()"
		textarea_style="height:auto; width: auto;"
		textarea_title="${gs.getMessage('Enter your comments here')}"
		ok=""
		ok_action="updateApproval"
		ok_id="change_confirm_ok_btn"
		ok_title="${gs.getMessage('')}"
		ok_type="button"
		ok_style_class="btn btn-primary disabled"
	/>
</j:jelly>

 

Hope this helps someone. 

View solution in original post

10 REPLIES 10

Sneha Chauhan
Kilo Contributor

Hi James,

 

I have a similar requirement for change request form and I am not very used to UI Pages and Jelly scripting.

I tried your code above but the approval state on approval record is not getting updated whereas comments are getting updated. The state remain as "Requested".

Can you please help me on this at the earliest?