The CreatorCon Call for Content is officially open! Get started here.

Incident to Create Request UI Action Functionality

keimo
Tera Contributor

Hello Community,

I'm working on a project that includes the following requirements:

  1. Create Service Catalog Item to request for a PC Refresh.
  2. Use the 'Create Request' UI Action functionality to create this request from an Incident.
  3. When clicking on Create Request, the UI Action should do the following:
    • In the incident, add note to Additional Comments stating that the incident was converted to a request.
    • Redirect to the Catalog Item and auto-populate the variables on the request.

The fields are auto-populate and redirects to the Catalog Item as required, however the fields continue to stay populated instead of clearing the values once the Catalog Item request is submitted. Any assistance with my scripting would be much appreciated.

Catalog Client Script:

function onLoad() {

    var inc = g_user.getClientData('related_incident');
    g_form.setValue('related_incident', inc);
    
    var req = g_user.getClientData('requested_for');
    g_form.setValue('requested_for', req);
        
    var mgr = g_user.getClientData('manager');
    g_form.setValue('manager', mgr);
        
    var loc = g_user.getClientData('employee_location');
    g_form.setValue('employee_location', loc);
        
    var com = g_user.getClientData('reason_computer_needed');
    g_form.setValue('reason_computer_needed', com);

    var dsk = g_user.getClientData('desk_number');
    g_form.setValue('desk_number', dsk);
    
    var add = g_user.getClientData('additional_details');
    g_form.setValue('additional_details', add);
    
}

UI Action:

var ses = gs.getSession();
ses.putClientData('related_incident', current.number);
ses.putClientData('requested_for', current.caller_id.sys_id.toString());
ses.putClientData('manager', current.caller_id.manager.sys_id.toString());
ses.putClientData('employee_location', current.location);
ses.putClientData('desk_number', current.caller_id.u_desk_area);
ses.putClientData('reason_computer_needed', 'PC Refresh/Upgrade');
ses.putClientData('additional_details', 'Converted to Computer Request from Incident Number: ' + current.number + '\n\n' + 'Incident Description: ' + '\n' + current.description);
current.comments = 'Incident converted to request for fulfillment. '; //Script doesn't populate Additional Comments in Incident

gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=51e2db16dbba1810a4c02d89139619d5');

 

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Keimo

You can include below lines before gs.setRedirect in UI action 

current.incident_state = '6';

current.close_code = 'Solved (Permanently)';

current.close_notes = 'Incident converted to request for fulfillment';
current.update();

I hope this answers your question.

 

- Pradeep Sharma

 

View solution in original post

21 REPLIES 21

Bharat Vasired1
Tera Contributor

Hi Kemo,

Did the answer mentioned by pradeep worked?

Bhavana Challa
Tera Contributor

Hello,
Could you please consolidate on the exact solution that you've implemented and working well.
Thanks 🙂