UI Action pop up to capture input

A Kose
Tera Contributor

Hi there,

 

I want to add a button/link 'Cancel Request' which is also visible from Portal view of a logged request. When clicked I want it to trigger a pop up message 'Please enter your reason for cancelling ticket' with a text field that takes the input from requestor and writes it to the applicable field work_notes.

 

I have created a UI Action where action name is 'cancel_request'. (see script below)

 

When I include the client script portion it pops up a screen on the form in the back end when clicked but doesn't update the record status (doesn't call the server script portion)  and the link doesn't show at all the portal side. 

 

When I exclude the client script portion, a link appears as expected on portal view of request and it cancels the record accordingly when clicked but I can't capture any input i.e. reason for cancellation.

I'd love to understand why this isn't working please.

Thanks  

 

//Client side onclick function
/*capture_reason();
function capture_reason(){
    var reason = prompt("Please enter your reason for cancelling ticket");
    if(reason){
    g_form.setValue('work_notes',  g_user.firstName + " " + g_user.lastName + " reason for cancelling: "+reason);
    gsftSubmit(gel('cancel_request'));
    } else {
        return false;
    }
}*/
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined'){
    cancelRequestItem();    
}
//Server-side function
function cancelRequestItem(){
    current.state = 7;
    current.active = false;
    current.work_notes = 'Request Cancelled';
    current.update();
    action.setRedirectURL(current);
}
2 REPLIES 2

Runjay Patel
Giga Sage

Hi @A Kose ,

 

Check my response on below thread. Follow the same approach to take the input on model and use them to update the record.

You need to tweak the logic a bit based your requirement but process you need to follow the same.

https://www.servicenow.com/community/virtual-agent-forum/ui-action-to-assign-incidents-to-problem/m-...

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Ankur Bawiskar
Tera Patron
Tera Patron

@A Kose 

client side UI actions won't work in portal

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader