UI Action for requested item

TMKAM
Tera Contributor

I have created a UI Action with button "Cancel Request" in the Requested Item.

Currently I have 2 issues as per below.

 

Issue 1

How to automatically insert the "Close Notes" with the Statement "Cancel Request by Requester" when Agent click on the "Cancel Request" button in Requested Item form?

 

Issue 2

How to automatically changes the Approval table (sysapproval_approver) in the Requested Item form from "Requested" to "No Longer Required" when Agent click on the "Cancel Request" button in Requested Item form?

 

The configuration as per below.

Table

Requested Item (sc_req_item)

 

Condition

current.approval == 'requested' && (gs.hasRole("bbraun_catalog_fulfillment_email") || gs.getUserID() == current.opened_by || current.u_requested_for == gs.getUserID())

 

Scripts

function reject() {
g_form.setMandatory('close_notes', 'true');
var answer = confirm("Are you sure you want to Cancel Request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'cancel_request'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined') {
current.state = '4';
current.approval = 'Cancelled';
//sysapproval_approver.state = 'not_required';
current.setWorkflow(false);
current.update();
}

 

Thank you in advance.

 

 

5 REPLIES 5

Hemanth M1
Giga Sage
Giga Sage

HI @TMKAM ,

 

1)add current.close_notes = "Cancel Request by Requester"

2)Cancel the workflow this would cancell all the approvals attached to the RITM , add this line 

new Workflow().cancel(current);
 
add both of them before setWorkflow(false) statemwent.
 
 
Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

TMKAM
Tera Contributor

@Hemanth M1 

Thank you for the solution but I'm not expert in these scripts and how do I put the solution into the current scripts i posted above?

Hi @TMKAM ,

 

did my reply answered your question , if so

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Hemanth M1
Giga Sage
Giga Sage

Hi @TMKAM 

 

I have added those lines your code, try this 

function reject() {
g_form.setMandatory('close_notes', 'true');
var answer = confirm("Are you sure you want to Cancel Request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'cancel_request'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined') {
current.state = '4';
new Workflow().cancel(current);  //cancel the workflow
current.close_notes = "Cancel Request by Requester"; //update close notes
current.setWorkflow(false);
current.update();
}

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025