Scripting with catalog variables on tasks (sc_item_option_mtom) table

nmartinez
Kilo Contributor

I am familiar with accessing [sc_item_option] and [sc_item_option_mtom] to query, modify and even create new catalog variables for request items via scripting; however I am trying to figure out how to associate catalog variables with newly created catalog tasks via scripting in the same fashion that it is done via the visual workflow.

I assume that there must be a related table that connects the catalog variables to the catalog task and then not unlike [sc_item_option_mtom] that would reference the catalog task's sys_id and the [sc_item_option] record. If there is such a table it does not have the "mtom" in the table's name. My second guess was that it would be either a script include or a business rule that is dynamically associating the variables to the catalog tasks. However I've yet to find any scripts that perform this function.

If anyone knows how to accomplish this, I would appreciate some help.

23 REPLIES 23

bt6lw
Giga Contributor

I know this is long overdue. I found this post while looking for the exact same requirement.




I could not find anything - but after much digging around I found out exactly how to do it.




There is a table named 'sc_item_variables_task';


There are two fields that are important. 1) Task. 2) Variable;



They are reference fields. If you put the task you have created and the variable you want to include in here, it will populate and show in the variable editor.




Code example.


var gr = new GlideRecord('sc_task');


gr.insert();




var add_task_var = new GlideRecord('sc_item_variables_task');


add_task_var.task = gr.sys_id;


add_task_var.variable = variablereference;


add_task_var.insert();


KingSukh
Tera Expert

One possible solution :


In your workflow you can add a Run Script block that can write the variables out to a table. You can add a reference field to this table from the sc_task table, and that way the fields in this table can be brought up in the slush bucket if you want to use this data at the sc_task level.



I am not sure if Eureka addresses this problem.


bt6lw
Giga Contributor

Sukhjinder.



There is no need to recreate the functionality that already exists.



The only trick is to reference the task sys id and variable sys id in the sc_item_variables_task table.


Hi Willem,



Can you bring the data from sc_item_variables_task table to show up in the slush bucket when creating list view for sc_task or task ?



Best Regards,


Sukhjinder S Gill


bt6lw
Giga Contributor

Of course.



If you want a related list on the sc_task you simply add the sc_item_variable_task table related list to the task or sc_task table.



There is a UI Macro, which put's it on the form for data entry and manipulation of the variable values already (which is what I was answering originally).



Let me know if you can't get it right, I will guide you through it.