Need help variable section on Catalog task

sunil maddheshi
Tera Guru

Hello everyone,

I am working on a requirement to create a set of automated tasks on a daily basis and assign them to a specific group. For this, we have a catalog item, and I have created a daily scheduled job that generates the RITM along with the associated catalog task for each product.

The scheduled job script is working as expected; however, the Variables section is not visible on the catalog task when it is created through the script. My requirement is to display the catalog item variables on the sc_task so that the assignee can fill them in before closing the task.

Below are the scheduled job script and the task screenshot for reference. Please help or suggest any alternative solution for this

// Submit Automated Task
var catalogItemSysId = 'e6067ec0c346725062c17ebdc0013130';
var sourceTable = 'u_automated_products';
var query = 'u_frequency=Daily^u_time_to_run=8 AM ET';

var gr = new GlideRecord(sourceTable);
gr.addEncodedQuery(query);
gr.query();

while (gr.next()) {

    var cartId = gs.generateGUID();
    var cart = new Cart(cartId, gs.getUserID());

    var item = cart.addItem(catalogItemSysId);
    cart.setVariable(
        item,
        'short_description',
        gr.u_product_name+" " + gs.nowDateTime()
    );

    var cartResult = cart.placeOrder();
    if (cartResult && cartResult.sys_id) {

        var requestSysId = cartResult.sys_id;
        gs.info('Request created: ' + requestSysId);

        var ritmGR = new GlideRecord('sc_req_item');
        ritmGR.addQuery('request', requestSysId);
        ritmGR.query();

        if (ritmGR.next()) {

            gs.info('RITM found: ' + ritmGR.sys_id);

            var scTask = new GlideRecord('sc_task');
            scTask.initialize();
            scTask.request_item = ritmGR.sys_id; 
            scTask.short_description = gr.u_product_name +" "+  gs.nowDateTime();
            scTask.description = 'Automated task created for '+gr.u_product_name;
            scTask.assignment_group = 'e8cf3e18c34ab25062c17ebdc0013155';
            scTask.state = 1;

            var taskSysId = scTask.insert();
            gs.info('SC Task created: ' + taskSysId);
        }
    }
}

sunilmaddheshi_0-1767249248434.png

 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Mega Patron

Hi @sunil maddheshi ,

ChaitanyaILCR_0-1767252215791.png

try setting variable's Global field value to true of your catalog item to 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

6 REPLIES 6

Shashank_Jain
Kilo Sage

Hi @sunil maddheshi ,

 

Variables are visible on catalog task if we submit the catalog item through the portal?

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

@Shashank_Jain  yes, when submitted though portal variables are visible.

Chaitanya ILCR
Mega Patron

Hi @sunil maddheshi ,

ChaitanyaILCR_0-1767252215791.png

try setting variable's Global field value to true of your catalog item to 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

@Chaitanya ILCR Thank you so much, it worked like magic.