logo

NJP

Create New Incident Button on USER FORM ( sys_user )

Import · May 08, 2021 · article

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.

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/create-new-incident-button-on-user-form-sys-user/ta-p/2330005