Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Displaying catalog variables on catalog task created by run script

PJ1
Tera Contributor

Hi, I have a requirement to create multple catalog task dimanically in workflow. I achived that by a run script using glide record. however Catalog variables are not showingup on the   tasks created. Did any one try showing catalog variables on tasks created by a script.

16 REPLIES 16

Less GlideRecord call of version above. Better or Same, not sure.

 

var scItemOptions = [];
var itemOptionNews = [];

var tsk = new GlideRecord('sc_task');
tsk.addQuery('request_item', current.sys_id);
tsk.query();

if (tsk.getRowCount() >= 1) {

    var reqvar = new GlideRecord('sc_item_option_mtom');
    reqvar.addQuery('request_item', current.sys_id);
    reqvar.query();

    while (reqvar.next()) {
        scItemOptions.push(reqvar.sc_item_option.sys_id);
    }

    if (scItemOptions.length >= 1) {

        var variablereference = new GlideRecord('sc_item_option');
        variablereference.addQuery("sys_id", "IN", scItemOptions.join(","));
        variablereference.query();
        while (variablereference.next()) {
            itemOptionNews.push(variablereference.item_option_new.sys_id);
        }

        if (itemOptionNews.length >= 1) {

            for (var i = 0; i < itemOptionNews.length; i++) {

                while (tsk.next()) {

                    var add_task_var = new GlideRecord('sc_item_variables_task');
                    add_task_var.task = tsk.sys_id;
                    add_task_var.variable = itemOptionNews[i];
                    add_task_var.insert();

                }

                tsk.restoreLocation(); // Reset Task Loop Location to 0

            }

        }

    }

}

Thanks stacey!! It worked for me