UI Action button transferring

AbooK
Tera Contributor

Hey, So I want to create an UI Action (a button) called "Transfer to Help2" on an incident form. This is in ServiceNow.

 

On an incident form we have a field called incident_type, so it can either be Help1 or Help2 as an incident type. And both of the form views has different fields on the form depending on if the incident_type is Help1 or Help2, but there is one specific field which Help1 does not have which is on Help2. So before the incident gets transfered over from Help1 to Help2 I want to be able to fill out that field which is a reference field called: u_system. This field must be filled before the incident can be transfered to Help2. I want this field to be filled out by the operator which is handling the incdient, and after its been filled out it can then be transfered over to Help2 so that the incident type is changed over to Help2.

 

How can I script this into my UI action button?

Any help is appreciated.

2 REPLIES 2

p_kanczugowski
Tera Guru

Hi, there are a few things to consider here. On the strictly functional level that'd address the case you're describing, you could use the following UI action

 

// this piece submits the form, which requires the mandatory fields to be filled in,
// and then calls the server script to set the incident type to help_2
function transferToHelpClient() {
    gsftSubmit(null, g_form.getFormElement(), 'transfer_to_help2');
}

if (typeof window === 'undefined') {
    transferToHelpServer();
}

function transferToHelpServer() {
    current.update();
    action.setRedirectURL(current);
}
 
p_kanczugowski_0-1709641036093.png

 

 
Then, if the field u_system is marked as mandatory, clicking the UI action will first check if the field is filled in.
 
However, this is a partial solution. What I would recommend is:
  1. A Data Policy that would ensure that u_system is truly mandatory (the "mandatory" flag on the sys_dictionary level is strictly client-side).
  2. Perhaps a condition in the UI action itself, to only show the button if the required field is not empty.

Please mark this response as useful and the question as solved if the issue has been solved. Thank you!

Tammy Simmons
Tera Guru

Hello @AbooK,

Here's a suggestion that might be helpful:

 

In the script section of your UI action, you can display your form view containing the 'u_system' field using a script similar to this, adjusting per your requirement.

 

function pickApprover(){
    //This will trigger the Approve for Approver business rule
   
    //Get the table name and sys_id of the record
    var tableName = g_form.getTableName();
    var sysID = g_form.getUniqueValue();
   
    //Create and open the dialog form
    var dialog = new GlideDialogForm('Approve for Approver', tableName); //Provide dialog title and table name
    dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
    dialog.addParm('sysparm_view', 'SetApproval'); //Specify a form view
    dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
    dialog.render(); //Open the dialog
}
 
Snag_dade65.png

The UI action includes a 'UI Action Visibility' related list. You can navigate here to exclude any views that you do not want to display when you click your UI action.

Snag_ddb88f.png

 

After clicking on the UI action, the script will open a dialog form displaying the specified form view containing the 'u_system' field.

Snag_e9bdd4.png

 If this information was helpful, please mark this answer as Accepted as Solution and hit the helpful button. Thank you!