Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dharma Liyanag
Tera Guru

New Incident Button on User Form

 

This is a sample logic to create,

  1. UI Action to create a button to Create New Incident
  2. Stay on the same page
  3. Display Related Incidents in the same sys_user form under related incident tab

 

 

UI Action ( script )

 

createIncident();

function createIncident() {

    // Create an Incident record

    // Populate the Caller, Short description, and Description fields with details from the NeedIt record

    var grInc = new GlideRecord("incident");

    // grInc.caller_id = current.u_requested_for;

 

    //     var usr = new GlideRecord('sys_user');

    //     if (usr.get('user_name', current.getValue('sys_created_by'))) {

    //         current.caller_id = usr.getValue('sys_id');

    //     }

    var usr = new GlideRecord('sys_user');

    if (usr.get('user_name', current.getValue('user_name'))) {

        current.caller_id = usr.getValue('sys_id');

    }

    var caller = current.caller_id; //current.user_name.getRefRecord();

    //Gets the sys_user GlideRecord for the caller

    grInc.caller_id = caller; //current.user_name;

    grInc.u_string_2 = current.phone;

    grInc.short_description = "FIVE9 INCIDENT -" + current.user_name + "-" + current.first_name;

    grInc.description = "Test request " + current.user_name + " requires some facilities work. " + caller;

    grInc.insert(); // Add Incident to database

 

    var sys_idd = grInc.getValue('sys_id');

 

    // Add a Work note to the NeedIt record indicating an Incident was created

    // Include the Incident Number in the Work note

    current.short_description = "FIVE9 INCIDENT " + grInc.number + " " + current.user_name + caller;

    current.description = "Test request " + grInc.number + " requires some facilities work. ";

    current.work_notes = "Incident " + grInc.number + " created to for the incoming call - five9";

    current.update(); // Update NeedIt record in database

}

action.setRedirectURL(current);

 

 

First page has entire script copied.

 

 

 

Comments
IcourtR
Giga Explorer

Create a button on the Incident form that allows users to mark an Incident as Resolved with a single click.

Version history
Last update:
‎05-08-2021 02:50 PM
Updated by: