Variables on NEW manually created tasks

kchorny
Tera Guru

We have a custom provisioning process that creates a request from an email, and two items (fulfillment and billing) within that request.   Each item has 'standard' tasks that are created via the workflow.   The provisioning team then has to create a bunch of new tasks within the item to complete the provisioning of services.  

I have a variable, req_details, that is visible on the items, and is visible on the auto-created catalog tasks. But when we create a new task within the item, the variable is not visible.   The Variable Editor is on the form (obviously, because we can see it on the other tasks...)

I'm at a loss as to why that field doesn't show on the manually created tasks.   Any ideas?

1 ACCEPTED SOLUTION

Hi kchorny



Write a before insert business rule on sc_task table and put this script in there.



(function executeRule(current, previous /*null when async*/) {


  var vars = new GlideRecord("item_option_new");


  vars.addQuery('cat_item', current.request_item.cat_item);


  vars.query();


  while (vars.next()) {


  insertVariable(vars.sys_id);


  }


  function insertVariable(id) {


  var gr = new GlideRecord('sc_item_variables_task');


  gr.initialize();


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


  gr.setValue('variable', id);


  gr.insert();


  }



})(current, previous);


View solution in original post

6 REPLIES 6

Abhinay Erra
Giga Sage

One reason I could think of is, when the tasks are created form the workflow, you do add the variables on to the form in the create task activity.


Correct.   So how do I get it to show up on tasks NOT created through the workflow?


Hi kchorny



Write a before insert business rule on sc_task table and put this script in there.



(function executeRule(current, previous /*null when async*/) {


  var vars = new GlideRecord("item_option_new");


  vars.addQuery('cat_item', current.request_item.cat_item);


  vars.query();


  while (vars.next()) {


  insertVariable(vars.sys_id);


  }


  function insertVariable(id) {


  var gr = new GlideRecord('sc_item_variables_task');


  gr.initialize();


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


  gr.setValue('variable', id);


  gr.insert();


  }



})(current, previous);


The above scrip works great on variables that are not in a variable set.   When I look at the table I dont see variable set variables included there.   Is there a way to include variable sets also?