Where are catalog item varliable's values stored and how do I put them on the RITM description via a workflow?

psenkow1
Giga Contributor

(I also posted this to the category Workflow because I wasn't sure which category it belongs in)

I have a catalog item that has several variables associated with it.  I thought the catalog item variables were stored in some table extended from sc_cat_item, but I have been unable to find it.

From within my workflow, in the RITM (request item) I want to (either or both):

1.  Set the short_description to one of the variables in the catalog item, or contatenate 2 of the variables.

2.  Set the description to all of the variables.  

We will ultimately want to display this in the Homepage, which is why I need it to be in the Short Description or Description, rather than in the "Variables" list on the RITM form.

I am afraid I have stepped way deeper than my JavaScript coding abilities!  

Has anyone else done this?  

 

Can anyone tell me what I need to do?

Your help is much appreciated!!

 

1 ACCEPTED SOLUTION

Raghu Loganatha
Kilo Guru

Patricia,



You can access the variable data by dot walking. In your case you can use the following as example



If you are trying to create a task by workflow try this:



task.short_Description = current.variable_pool.<Field_name>   // Add your field name


task.description = current.variable_pool.<field_name> // Field name which you want to add in description


task.description += current.variable_pool.<field_namne> // You have add += here because you want to add on top of above line




**Posting your question in category called "Developer Community" will reach out to many developers.


View solution in original post

4 REPLIES 4

amis
Kilo Expert

Hi Patricia,



Variable values are stored in table sc_item_option_mtom



1. You can   access variable information on RITM using:-


${variables.YOUR_VARIABLE_NAME}



2. The below script copies all the variable questions alongwith answers into description field


you can modify as per your requirement



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


  // Copy variable info into description


  var varArr='';



  var set = new GlideappVariablePoolQuestionSet();


  set.setRequestID(current.sys_id);


  set.load();


  var vs = set.getFlatQuestions();


  for (var i=0; i < vs.size(); i++) {


// add to remove any unwanted variables


  if((vs.get(i).getLabel() != '') && (vs.get(i).getDisplayValue()!= '') && (vs.get(i).getLabel() != 'Requestor')) {


  varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';


  }


  }


  current.description=varArr;



})(current, previous);



PS: Please mark helpful / Correct or hit like based on my response



Thanks,


Abhi


This is exactly what I was looking for in particular. Really appreciate this code.

Raghu Loganatha
Kilo Guru

Patricia,



You can access the variable data by dot walking. In your case you can use the following as example



If you are trying to create a task by workflow try this:



task.short_Description = current.variable_pool.<Field_name>   // Add your field name


task.description = current.variable_pool.<field_name> // Field name which you want to add in description


task.description += current.variable_pool.<field_namne> // You have add += here because you want to add on top of above line




**Posting your question in category called "Developer Community" will reach out to many developers.


Aditya Telideva
ServiceNow Employee
ServiceNow Employee

I would recommend please go through the below link:



Coding Best Practices - ServiceNow Wiki



Thanks,


aditya telidevara (Adi)