Reject button not rejecting approval request

Aaron Duncan
Mega Sage

I have a reject button where the Client box is checked, and the onclick field has the onRejectingBIR() function set. 

The button shows up, and moves the record to the correct state. It even sends the comment to the work notes as expected. The only thing not working is rejecting the approval record. 

Can anyone see what I'm doing wrong?

 

var currentRec = g_form.getUniqueValue();
var currentUser = g_user.userID;

function onRejectingBIR() {
    loadConfirmDialog();
    moveToCancel();
}

function loadConfirmDialog() {
	//Display popup to capture reason for rejection.
    var rejectconfirmDialog = new GlideModal('reject_approval_global');
    rejectconfirmDialog.setTitle(new GwtMessage().getMessage("Rejection Reason:")); //Modify title to display on popup
    rejectconfirmDialog.render();
}

//  gsftSubmit(null, g_form.getFormElement(), "reject");

function moveToCancel(currentRec,currentUser) {
    g_form.setValue("state", 11) //set state to Fix Implemented.
	
	//Find the associated approval record and set it to rejected.
    var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', currentRec);
	gr.addQuery('state','requested');
	gr.addQuery('approver', currentUser);
    gr.query();
    while (gr.next()) {
        gr.state = 'rejected';
        gr.update();
    }
    setRedirect();
}

function setRedirect(current) {

    current.update();
    action.setRedirectURL(current);
}
1 ACCEPTED SOLUTION

I figured it out. 

I moved the variables into the function, and they were able to finish the rejection.

function moveToCancel(currentRec,currentUser) {
 currentRec = g_form.getUniqueValue();
 currentUser = g_user.userID;
 
    g_form.setValue("state", 11) //set state to Fix Implemented.
	
	//Find the associated approval record and set it to rejected.
    var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', currentRec);
	gr.addQuery('state','requested');
	gr.addQuery('approver', currentUser);
    gr.query();
    while (gr.next()) {
        gr.setValue('state','rejected');
        gr.update()
    }
    setRedirect();
}

View solution in original post

4 REPLIES 4

Mahathi
Mega Sage
Mega Sage

Hi @Aaron Duncan ,

You can try passing the parameters explicitly 

moveToCancel(currentRec, currentUser);

Also while setting the value: 

gr.setValue('state', 'rejected'); 

current.update works on the server side, take a look at the last part of the function, if a save could do the job.

If my answer helped in any way, please mark it as Correct & 👍Helpful

Regards,
Mahathi



@Mahathi none of the above worked. Any other ideas?

I figured it out. 

I moved the variables into the function, and they were able to finish the rejection.

function moveToCancel(currentRec,currentUser) {
 currentRec = g_form.getUniqueValue();
 currentUser = g_user.userID;
 
    g_form.setValue("state", 11) //set state to Fix Implemented.
	
	//Find the associated approval record and set it to rejected.
    var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', currentRec);
	gr.addQuery('state','requested');
	gr.addQuery('approver', currentUser);
    gr.query();
    while (gr.next()) {
        gr.setValue('state','rejected');
        gr.update()
    }
    setRedirect();
}

Mahathi
Mega Sage
Mega Sage

Ok great @Aaron Duncan .

But still the value setting and current.update sure would've been helpful i feel. 

Regards,
Mahathi