Convert an incident into a Request

BiyazatE
Tera Contributor

Hey ,

I have a requirement to make a ui action that onClick convert incident into a Request.

It should populate a few fields from incident table as well as the worknotes.

 

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@BiyazatE You will not be able to convert an existing incident into a request. However, you can create a new request from an incident using the UI Action.

 

Create a New UI Action

  1. Navigate to System Definition > UI Actions.
  2. Click New to create a new UI Action.

2. Configure the UI Action

Fill out the form with the following details:

  • Name: Create Request from Incident
  • Table: Incident (incident)
  • Action name: create_request
  • Condition: current.active == true (or any other condition you want to apply)
  • Form Button: Checked
  • Show insert: Checked (if you want it available on insert)
  • Show update: Checked (if you want it available on update)

3. Script for the UI Action

In the Script section, you'll write the code to create a new request from the incident. Below is an example script:

 

(function executeAction() {
    // Ensure the current record is valid and active
    if (current == null || !current.active) {
        gs.addErrorMessage('Incident is either not valid or not active.');
        return;
    }

    // Create a new request record
    var request = new GlideRecord('sc_request'); // or the appropriate table for your request
    request.initialize();
    
    // Set fields on the request based on the incident
    request.setValue('short_description', 'Request from Incident: ' + current.number);
    request.setValue('description', current.description);
    request.setValue('u_incident_reference', current.sys_id); // Assuming you have a reference field on the request to link to the incident
    request.setValue('requested_for', current.caller_id); // Assuming 'caller_id' is the requested_for person
    request.insert();

    // Optional: Create a corresponding catalog item if needed (linked RITM)
    var ritm = new GlideRecord('sc_req_item');
    ritm.initialize();
    ritm.setValue('request', request.sys_id);
    ritm.setValue('short_description', 'RITM linked to incident ' + current.number);
    ritm.setValue('cat_item', '<your catalog item sys_id>'); // Set the catalog item
    ritm.insert();

    // Provide feedback to the user
    gs.addInfoMessage('New request created from Incident: ' + current.number);

    // Redirect to the newly created request
    action.setRedirectURL(request);
})();

Brian Lancaster
Tera Sage

Take a look at the out of the box UI Action to do this. It does everything except populating fields and work notes. One field that does come over is the caller gets set as the requested field.