Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to store catalog variable's values data into another table in service now??

priyanka0709
Tera Contributor

We have created catalog item after the submission the values of variable need to store into Custom table.

How can we implement this in an appropriate way. please guide us.

1 ACCEPTED SOLUTION

Alp Utku
Mega Sage

You can satisfy your requirement without writing any code.

 

1) Trigger = Service Catalog 

 

2) Use "Get Catalog Variables" action to get variables from your catalog Item

 

3) Use "Create Record" action and select your table. Then, match table fields with catalog Item variables

 

4) You can close the RITM by using "Update Record" action accordingly.

 

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi @priyanka0709 ,

  You can write a Before Business rule on sc_req_item and add the following script in there.

 

when: before insert

 

script:

 

var set = new GlideappVariablePoolQuestionSet();

 

  set.setRequestID(current.sys_id);

 

  set.load();

 

  var vs = set.getFlatQuestions();

 

  var varArr='';

 

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

 

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

 

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

 

  }

 

  }

 

  var gr= new GlideRecord('sc_request');

 

  gr.get(current.request);

 

  gr.description=varArr;

 

  gr.update();

 

Stefan Georgiev
Tera Guru

Hello @priyanka0709 ,

i am not sure why you need to do that bu you can do that in the flow designer, create an custom action and pass the sys_id of RITM <input of the action is the sys_id of RITM>

Then you do something like this 

(function execute(inputs, outputs) {
var gr = new GlideRecord('sc_item_option_mtom'); // this is that table stat stores you variables options
gr.addQuery('request_item' , inputs.source);
gr.query();
 
var variablesObj = {}

while (gr.next()) {
 
  variablesObj[gr.sc_item_option.item_option_new.name] = gr.sc_item_option.value + ''
 
}
 
var targetTable = new GlideRecord(<your custom taable>)
targetTable.initialize()

for( var field in variablesObj ) {
   targetTable[field] = variablesObj[field] // this is going to work only if your fields in the custom table have the same name as the variables in the catalog item, else you are going to need to map them manually one by one 
}
 
targetTable.update()

})(inputs, outputs);

I haven't tried this just wrote it in here, test it first

Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan

What should be the table name and when it will run?

Do we need to give same variable name into custom table?

 

Hello @priyanka0709,

I was thinking more of a scripting approach, used when you want to copy variables from one RTIM to another, but @Alp Utku is going to be more user-friendly.
You should go that way and map your variables to whatever variables of your custom table you want, using just the data from your Get Catalog Variables activity.

Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful.

All the Best,
Stefan