Retrieving a rejection reason from an approval and placing it in a field in a request within Workflo

WarrenB
Tera Expert

I do not usually work within the Workflow Editor.  And I'm not a great scripter, so of course that's what I must work with right now!

 

We have added a rejection reason onto the approval form.

We have created a new request form for our customers to request Non-Standard Software.

 

Within the workflow, there is an approval step.  To reject the request, we require a reason.  If it is rejected, then the request is canceled and the user is notified.

WarrenB_0-1685996024189.png

 

It's the "run script" step I am struggling with.  I wrote a very simple script to retrieve the rejection reason and set it in the current record.

 

 

var rejectReason = new GlideRecord('sysapproval_approver');
rejectReason.addQuery('document_id',current.sys_id);
rejectReason.addQuery('state', 'rejected');
rejectReason.query();

if(rejectReason.next()) {
	current.cancel_reason = rejectReason.u_rejection_reason;
	current.setWorkflow(false);
	current.update;
}

 

 

I'm fairly confident by issue is with the last few lines.  I'm just not sure what the appropriate syntax should be.

Any help would be most appreciated!

 

Warren Baltimore

1 ACCEPTED SOLUTION

WarrenB
Tera Expert

Well, I solved it.  I went a different route with this-

var rejectReason = new GlideRecord('sysapproval_approver');
var tgtRec = new GlideRecord('u_atf_new_software');
rejectReason.addQuery('document_id',current.sys_id);
rejectReason.addQuery('state', 'rejected');
rejectReason.query();

if(rejectReason.next()) {
	tgtRec.addQuery('sys_id',current.sys_id);
	tgtRec.query();
	
	if(tgtRec.next()) {
		tgtRec.u_cancel_reason = rejectReason.u_rejection_reason;
		tgtRec.autoSysFields(false);
		tgtRec.update();
	}
}

Works quite well!

View solution in original post

1 REPLY 1

WarrenB
Tera Expert

Well, I solved it.  I went a different route with this-

var rejectReason = new GlideRecord('sysapproval_approver');
var tgtRec = new GlideRecord('u_atf_new_software');
rejectReason.addQuery('document_id',current.sys_id);
rejectReason.addQuery('state', 'rejected');
rejectReason.query();

if(rejectReason.next()) {
	tgtRec.addQuery('sys_id',current.sys_id);
	tgtRec.query();
	
	if(tgtRec.next()) {
		tgtRec.u_cancel_reason = rejectReason.u_rejection_reason;
		tgtRec.autoSysFields(false);
		tgtRec.update();
	}
}

Works quite well!