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

PJ1
Tera Contributor

Anurag,



I want to display the variables from request item on the catalog task. Like the way we do it by selecting variables in field "Variables on Task Form[Slush bucket]" in catalog task activity, but by a script.


OK, what I'm going to tell you now will create performance problems if you don't handle them properly.



One way to copy variables from RITM to Task is by using a Script, that takes all the variables from the RITM and then creates them on the TASK. I'm not sure if there are better solutions to this.



The following is the outline:


getSetOPSVars();




function getSetOPSVars() {


 


    var gr = new GlideRecord("item_option_new"); // go to item option new table, where all the variables are stored.


    gr.addEncodedQuery('variable_set=40aed32c7031910042fadc74bf258716^ORvariable_set=077c5c9f75a5f00042fa87e815140de6^ORvariable_set=f63e0bee3534200042fa4e78a10a2a5f^ORvariable_set=98421c95e9d3200042fa00182908177b^ORcat_item=bd419b2ae847200042faa6cac41b71d6');//get all your variables that belong to this Catalog item, you WILL have to modify this query.


    gr.query();


    while(gr.next()){


          insertVariable(gr.sys_id); //start inserting that variable again for each catalog task you just created.


    }


 


}


function insertVariable(id) {


    var gr = new GlideRecord('sc_item_variables_task');//sc_item_variables_task is the table that stores the variables for variable editor on Catalog Task


    gr.initialize();


    gr.setValue('task', current.sys_id);


    gr.setValue('variable', id);


    gr.insert();


 


}



Again, you have been warned. three years ago when they came to me with this requirement, I happily did that for them. Now if they ask me to do this again, I wont because you are just duplicating the Variables of RITM on Task. You should do the same too, you should go back to them and fig out a way to divert them to RITM page.


Adding records to the sc_item_variables_task table seems like what the system does anyway, when it creates a task and displays the variable on the task record.


Kalaiarasan Pus
Giga Sage

I would go about handling this bit differently and would adapt a more basic approach using simple Iframes.



First step > Create a new view of RITM and add just the variable editor to the form layout.



Second step can be done in 2 ways.


  1. Create a Iframe dynamically (http://www.dyn-web.com/tutorials/iframes/dyn-gen/) OR
  2. Use formatter to add a iframe to the form


The Iframe is the display handler and displays the new view created that just has the variable editor.



Third, make use of any onload script/ui policy to load the 'src' attribute of the iframe with the new view of the RITM (dynamically form the URL).



Benefits :


  • No extra glide record. DB friendly
  • All the out of the box things are being used. Hence no hassles during upgrades.


If any of the steps seems misleading or confusing, let me know


One more thing to add, the headers and the buttons would be visible in the Iframe. So will check if that can be avoided as well ...