Transform Script for Variable Set and Catalog Items

Ehab Pilloor
Mega Sage

Hi all,

I have imported a catalog item through excel sheet (using Import sets and Transform map), I then imported Variable sets followed by Variables into their respective tables using same method, then I had to add the variable set in the catalog item manually. everything worked perfectly fine. Now that I want to Import Variable set such that I don't have to add it manually to the catalog item. after importing variable set it must be directly appearing in the variable sets of catalog item.

 

Can anyone help with the solution?

 

Thanks and Regards,

Ehab Pilloor

1 ACCEPTED SOLUTION

Ubada Barmawar
Giga Guru

Hi @Ehab Pilloor 

 

for a variable set to appear in catalog item, a record must be present in 'io_set_item' table which has two reference fields "variable set" and "catalog item".

 

you can write an OnAfter Transform script to create a record on the 'io_set_item' table, and the catalog item will automatically have the imported variable set.

 

  1. (function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
  2.  
  3.     var gr = new GlideRecord('io_set_item');
  4.     var grsc = new GlideRecord('sc_cat_item');
  5.     grsc.addQuery('name', source.u_catalog_item);
  6.     grsc.query();
  7.    
  8.     if(grsc.next())
  9.     {
  10.         gs.log(grsc.getUniqueValue());
  11.         gr.setValue('sc_cat_item', grsc.getUniqueValue());
  12.     }
  13.     gr.setValue('variable_set', target.getUniqueValue());
  14.     gr.insert();
  15. })(source, map, log, target);
 
note : 
source.u_catalog in line5 is for getting the value from import set table (field: Catalog Item, type: string)
 
hope this help, if yes please mark it as accepted and helpful.
 
regards,
Ubada Barmawar
 

View solution in original post

2 REPLIES 2

Ubada Barmawar
Giga Guru

Hi @Ehab Pilloor 

 

for a variable set to appear in catalog item, a record must be present in 'io_set_item' table which has two reference fields "variable set" and "catalog item".

 

you can write an OnAfter Transform script to create a record on the 'io_set_item' table, and the catalog item will automatically have the imported variable set.

 

  1. (function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
  2.  
  3.     var gr = new GlideRecord('io_set_item');
  4.     var grsc = new GlideRecord('sc_cat_item');
  5.     grsc.addQuery('name', source.u_catalog_item);
  6.     grsc.query();
  7.    
  8.     if(grsc.next())
  9.     {
  10.         gs.log(grsc.getUniqueValue());
  11.         gr.setValue('sc_cat_item', grsc.getUniqueValue());
  12.     }
  13.     gr.setValue('variable_set', target.getUniqueValue());
  14.     gr.insert();
  15. })(source, map, log, target);
 
note : 
source.u_catalog in line5 is for getting the value from import set table (field: Catalog Item, type: string)
 
hope this help, if yes please mark it as accepted and helpful.
 
regards,
Ubada Barmawar
 

Sumanth16
Kilo Patron

Hi @Ehab Pilloor ,

 

Please refer to below thread":

https://www.servicenow.com/community/developer-forum/how-do-i-transform-a-value-into-a-variable-and-...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,
Sumanth Meda