Workflow Script to Populate Table with Variables

alexcharleswort
Tera Expert

So, I haven't seen this question yet or anything similar that I can alter to make fit. Maybe I am just using the wrong key words to look it up...

What I want to have happen is when certain variables are filled out on the task level, I want those variables to be directed toward a second and entirely separate table.

When a customer goes into the request, they fill out what they want for hardware and then as the tasks are completed, the fulfiller fills out variables that are only visible on the task level like what model and the cost. At the end of the workflow, I want to add a run script that adds the model and cost to our cell_phone table.

This is outside of my scripting experience so any help would be awesome if this is at all possible.

Thanks!

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Alex,



You can use Workflow Input Variables and then a run script activity to set the values. With workflow input variables you can create variables associated with your workflow that do not show up on any front end catalog items. You can then add one or more of those variable to a catalog task activity in the workflow and force the person updating the task to add a value. You can then later reference those variables in a run script activity in your workflow.



For example, if you added a variable named workflow_ci and wanted to assign it to the requested for user you could use the following script in your run script activity.



(function(){


      var ci = new GlideRecord('cmdb_ci');


      if (ci.get(current.variables.workflow_ci)) {


              ci.assigned_to = current.request.requested_for;


              ci.update();


      }


})();



If you wanted to do something like create records instead of update you could do that as well.


Yes, what I am trying to do is make a new record unless it matches the employee id in the cell table, and then it updates that record for that person. I already have the variables that need to be filled in after the request is submitted hidden and mandatory. So, I just need the proper script to take those variable on the item and put it into the cell table. the script that I have been tweaking is



(function(){


var cell = new GlideRecord('u_susie_cells');


if (cell.get(current.variables.workflow_cell).isValidRecord()){


  cell.u_staff_member_name = current.variables.Who_is_this_for;


  cell.u_employee_id = current.variables.staff_id;


  cell.u_plan_name = current.variables.plan_name;


  cell.u_carrier = current.variables.carrier;


  cell.update();


 


}


})();



I've tried variations such as current.variabes , current.request , current.request.variables. None seem to work. is there something else in my script that is off?


Right now I am mainly working to see if I can just get a new record populating in the workflow. I will work on the updating bit later.


What value do you get when you log current.variables.workflow_cell?