Autopopulate variable value

abhisek
Tera Contributor

I am working on a requirement. Using UI Action creating a request from an Incident. Once we click on the UI Action a request will be created and incident will be cancelled. This portion is working.

There are 3 variables on the catalog item for example abc, def and xyz.

abc should be auto populated as per the incident short description, def should be auto populated as per the incident description and xyz should be auto populated as per the incident urgency. This portion is not working.

Below is the script I have written:

 

(function executeRule(current, previous /*null when async*/) {
    try {
       
        var requestGr = new GlideRecord('sc_request');
        requestGr.initialize();
         requestGr.requested_for = current.caller_id;
        // requestGr.abc = current.short_description;
        // requestGr.def= current.description;
        // requestGr.xyz= current.urgency;

        var requestID = requestGr.insert();
 
        var itemGr = new GlideRecord('sc_req_item');
        itemGr.initialize();
        itemGr.request = requestID;
        itemGr.cat_item = 'sysid of the catalog item';
        itemGr.requested_for = current.caller_id;
        var itemID = itemGr.insert();

        // Update the RITM with the request summary, description, and urgency
        itemGr.abc= current.short_description;
        itemGr.def= current.description;
        itemGr.xyz= current.urgency;
        itemGr.update();

       
Can anyone please help me out, it is urgent.
     
6 REPLIES 6

Harish_K07
Giga Guru

Hi @abhisek  

 

In your script,  itemGr.abc is simply going to update the RITM fields. Not the variables.

For Variables, you need to do something like this: itemGr.variables.abc= current.short_description;

 

Mark as correct and helpful if it solved your query.

Regards,

Harish

Hi @Harish_K07 

 

Tried with  itemGr.variables.abc= current.short_description; but not working.

Hi @Harish_K07 

Both the catalog item and UI action are in different application scope.

HrishabhKumar
Kilo Sage

Hi @abhisek  ,

I believe abc, def, xyz are variable of catalog item, so they won't be set if you are Gliding into "sc_request" table. Try removing the code from there and set the all the field later in the script where you are Gliding into the "sc_req_item" table.

I've updated the code, pasted below:

(function executeRule(current, previous /*null when async*/) {
    try {
       
        var requestGr = new GlideRecord('sc_request');
        requestGr.initialize();
         requestGr.requested_for = current.caller_id;
        var requestID = requestGr.insert();
 
        var itemGr = new GlideRecord('sc_req_item');
        itemGr.initialize();
        itemGr.request = requestID;
        itemGr.cat_item = 'sysid of the catalog item';
        itemGr.requested_for = current.caller_id;
        var itemID = itemGr.insert();

        // Update the RITM with the request summary, description, and urgency
        itemGr.abc= current.short_description;
        itemGr.def= current.description;
        itemGr.xyz= current.urgency;
        itemGr.update();

 

Thanks.