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.

Once Request is created from the incident close the incident

Debasis Pati
Tera Guru

OOB there is a ui Declarative action called Create request in the incident table for Sow.
once clicked on it it asks which catalog item you want to order once you select and submit it creates one request.
My need is once a request gets created it should close the incident from where we have navigated and created the request.
below is the declarative action code:

function onClick() {
    var result = g_form.submit('sysverb_ws_save');
    if (!result) {
        //failed form submission
        return;
    }
    result.then(function() {
        var params = {};
        params.sysparm_parent_table = "incident";
        params.sysparm_parent_sys_id = g_form.getUniqueValue();
        g_service_catalog.openCatalogItem('sc_cat_item', '-1', params);
    });
}
How i can achieve my requirement ?   @Ankur Bawiskar  any idea?
2 ACCEPTED SOLUTIONS

@Ankur Bawiskar ,
I tried the below whenever a request gets created from incident the parent field in the request gets updated.

i created one after business rule on request table putting the conditions as parent is not empty and class name is incident and below is the script to close the incident.

 var inc = new GlideRecord('incident');
    inc.addQuery('sys_id', current.parent);
    inc.query();
    if (inc.next()) {
        inc.state = '7';
        inc.close_code ='Resolved by request';
        inc.close_notes ="Request "+current.number+" created";
        inc.update();
    }
Yes before closing the incident we definitely need resolution code and notes as there is a data policy.
Is this approach correct @Ankur Bawiskar ?
 

View solution in original post

@Debasis Pati 

I think you marked your own response as correct.

Would you mind marking my response as correct as I suggested approach and also validated your current approach?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Hello @Ankur Bawiskar ,
continue to this when i click on create change request that value should get copied to the catalog item requested for variable.
Is this possible also the requested for variable in the item have default value as logged in user.

@Debasis Pati 

recently I shared solution on community question as well

Hi Team, In service operation Workspace under interaction record we have UI actions which is Create 

I also created a blog for that check that and enhance

Invoke record producer within Configurable workspace, send parameter & fetch the value

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar ,
This is really good but one question in this way we need to create the on load catalog client script in all the catalog items right?

@Debasis Pati 

that's correct.

OR

You can create a variable set to hold Requested For and then write onLoad on this variable set and then include this variable set in your whichever catalog items you want

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

mohitbhadan
Tera Contributor

 

I created an After Business Rule on the Request (sc_request) table with the following conditions:

  • parent is not empty

  • parent_table is "incident" (class name = incident)

  • When = After Insert

Business Rule Script

 

(function executeRule(current, previous) {

if (current.parent && current.parent_table == "incident") {

// Retrieve the parent Incident
var inc = new GlideRecord("incident");
inc.addQuery("sys_id", current.parent);
inc.query();

if (inc.next()) {
// Close the Incident
inc.state = 7; // Closed
inc.close_code = "Resolved by request"; // Resolution code
inc.close_notes = "Request " + current.number + " created";
inc.update();
}
}