Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

create incident and request from the same catalog form

PK14
Kilo Guru

Hi Team,

We have a requirement to streamline the process of ticket creation. The business would like to avoid maintaining multiple forms and instead use a single catalog item/form. Based on the selected "Type of Issue", the system should automatically determine whether to create an Incident or a Request.

For example:
If the issue type is Network & Connectivity, then an Incident should be created.
If the issue type is Administration Documentation, then a Request should be created.

Kindly suggest the best approach to implement this, along with the recommended steps for configuring the creation of both Incident and Request from a single form.

Wrote a record producer code but doesn't create a request record.

(function producerScript(current, producer) {
    var issueType = producer.category;
    // -------- INCIDENT CATEGORIES --------
    var incCategories = [
        'Power & Electrical',
        'Hardware & Infrastructure',
        'Network & Connectivity',
        'Storage & Compute',
        'Monitoring, Telemetry & DCIM',
        'Facilities & Physical Environment',
        'Colocation / Vendor Issues',
        'Change & Human Error',
        'General / Miscellaneous'
    ];
    if (incCategories.indexOf(issueType) > -1) {
        var inc = new GlideRecord('incident');
        inc.initialize();
        inc.short_description = producer.short_description || issueType;
        inc.description = producer.description || "";
        inc.caller_id = gs.getUserID();
        inc.insert();
        action.setRedirectURL(inc);
        gs.addInfoMessage("Incident created for category: " + issueType);
        return;
    }

   
    // -------- REQUEST CATEGORIES --------
    var reqCategories = [
        'Power & Environmental',
        'Infrastructure & Buildouts',
        'Connectivity & Circuits',
        'Asset & Lifecycle Management'
    ];
    if (reqCategories.indexOf(issueType) > -1) {
 
        var reqGr = new GlideRecord('sc_request');
        reqGr.initialize();
        reqGr.requested_for = gs.getUserID();
        reqGr.short_description = producer.short_description || issueType;
        var reqSysId = reqGr.insert();
       
        var ritm = new GlideRecord('sc_req_item');
        ritm.initialize();
        ritm.request = reqSysId;
        ritm.short_description = producer.short_description || issueType;
        ritm.description = producer.description || "";
        var ritmSysId = ritm.insert();
        action.setRedirectURL(ritm);
        gs.addInfoMessage("Request created for category: " + issueType);
        return;
    }
})(current, producer);



5 REPLIES 5

Raghav Sharma24
Giga Patron

@PK14 You do not have to insert anything into req/REITM or sc_task table that is automatically handled by servicenow cart API.

 

Refer : https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc... 

 

This is a server side code and can be written in record producer script or any other script like BR or script include.