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

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Debasis Pati 

why would you close the INC?

If you still require use GlideAjax here and mark the INC as closed/resolved.

Do remember Resolution Code and Notes are mandatory during INC closure/resolve so set those fields properly

function onClick() {
    var result = g_form.submit('sysverb_ws_save');
    if (!result) {
        //failed form submission
        return;
    }
    result.then(function() {

       // GlideAjax here

        var params = {};
        params.sysparm_parent_table = "incident";
        params.sysparm_parent_sys_id = g_form.getUniqueValue();
        g_service_catalog.openCatalogItem('sc_cat_item', '-1', params);
    });
}

💡 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

@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 ?
 

@Debasis Pati 

yes either put it in Declarative Action or use after insert BR on REQUEST table

💡 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

@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