converting request from incident using ui action

abhisek
Tera Contributor

We have a catalog item for example 'request anything'. Manually to create a request for this catalog item after mentioning all the mandatory field details we need to click on 'proceed to checkout' and the need to click on 'checkout' to submit a request.

Using UI Action on incident form, we want to create a request for that catalog item 'request anything'. The UI Action is in Service Operation Application scope and the catalog item is in global scope.

By using the below script, I am trying to submit a request, but this script is not submitting the request.

 

 

(function executeRule(current, previous /*null when async*/ ) {

gs.addInfoMessage('SOW Inside');

var cart = new sn_sc.CartJS();
var item = {
"sysparm_id": "sys id of the catalog item",
"sysparm_quantity": "1",
"variables": {
"request_summary": "short_description",
}
};
// var cartDetails = cart.addToCart(item);
var request = cart.checkoutCart();

// gs.addInfoMessage('SOW request_id ' + request.request_id);
gs.addInfoMessage('SOW request ' + JSON.stringify(request));

 

})(current, previous);

 

Can anyone please help me out, it is so urgent.

8 REPLIES 8

Yashsvi
Kilo Sage

Hi @abhisek ,

please check below link:

https://www.servicenow.com/community/itsm-forum/convert-incident-to-request-via-ui-action/td-p/57168...

Thank you, please make helpful if you accept the solution.

Hi @Yashsvi 

 

The UI Action is in Service Operation Application scope and the catalog item is in global scope.

Hi @abhisek ,

To convert an incident to a request using a UI action in the Service Operation application scope while the catalog item is in the Global scope, follow these concise steps:

 

1. Configure Cross-Scope Access:

   - Navigate to System Definition > Application Cross-Scope Access

   - Grant the Service Operation scope access to necessary Global scope resources.

 

2. Create a Script Include in the Global Scope:

   - In the Global scope, create a Script Include (e.g., `RequestUtil`):

 

 

 

var RequestUtil = Class.create();
     RequestUtil.prototype = {
         initialize: function() {},
         createRequestFromIncident: function(incidentId, catalogItemId) {
             var request = new GlideRecord('sc_request');
             request.initialize();
             request.requested_for = gs.getUserID();
             request.requested_by = gs.getUserID();
             request.short_description = 'Request from Incident ' + incidentId;
             request.source = 'incident';
             var requestId = request.insert();
 
             if (requestId) {
                 var ritm = new GlideRecord('sc_req_item');
                 ritm.initialize();
                 ritm.request = requestId;
                 ritm.cat_item = catalogItemId;
                 ritm.short_description = 'Request Item from Incident ' + incidentId;
                 ritm.insert();
                 return requestId;
             }
             return null;
         },
         type: 'RequestUtil'
     };

 

 

 

3. Create a UI Action in the Service Operation Scope:

   - Navigate to System UI > UI Actions in the Service Operation scope.

   - Create a UI Action for the `incident` table with the script:

 

 

 

(function executeAction() {
         if (current.isNewRecord()) {
             gs.addErrorMessage('Save the incident before converting.');
             return;
         }
 
         var catalogItemId = 'YOUR_CATALOG_ITEM_SYS_ID';
         var requestUtil = new global.RequestUtil();
         var requestId = requestUtil.createRequestFromIncident(current.sys_id, catalogItemId);
 
         if (requestId) {
             gs.addInfoMessage('Request created: ' + requestId);
action.setRedirectURL('/sc_request.do?sys_id=' + requestId);
         } else {
             gs.addErrorMessage('Failed to create request.');
         }
     })();

 

 

 

4. Test the UI Action:

   - Open an incident, click the `Convert to Request` button, and verify that a request is created.

Thank you, please make helpful if you accept the solution.

Hi @Yashsvi 

Thanks for your reply. The above script is working. I have to populate RITM variable values as well as per the incident description, short description and urgency.