How to create variable using script?

ishaanvohra
Kilo Contributor

Hi,

Can we create variables of Catalog Item by using script?I want to create a Catalog Item and its Variables by using a script?

Plz help me out how can I create variables through scripting?

1 ACCEPTED SOLUTION

dev_vijaysnowhy
Giga Contributor

hello Ishaan I got this answer from the community itself hope it would be helpful



I've done something similar recently, with new applications being added to the catalog from a script running on the software models table, so when a software model gets signed off, it appears in the catalog automatically.



I've used a Workflow to handle the whole process, with a Script object that actually creates the object.



The concept behind the script is very straightforward:   a gliderecord onto the sc_cat_item table that creates a new record, and sets all the values from the data received by the web service (I don't know enough about web services to answer how you'd achieve that).   If you want to add a set of variables, I suggest you set the required variables up as a variable set, then use another glide record to create an entry on table 'io_set_item', adding the new item to the variable set, adding the variables.



Here are some bits of script that might help..




  1. var cat_item = new GlideRecord('sc_cat_item');  
  2. cat_item.newRecord();  
  3.  
  4. cat_item.name = (current.name);  
  5. cat_item.no_quantity = 'true';  
  6. cat_item.omit_price = 'true';  
  7. cat_item.workflow = 'd1a7905b0fc44ec43276f55be1050eea';  
  8. cat_item.sc_catalogs = '052590b10fabb1003276f55be1050eb5';  
  9. cat_item.owner = (current.owner.name);  
  10. cat_item.u_pid = (current.u_pid);  
  11. //set category to be lowest level defined  
  12.  
  13. //cat_item.price = (current.price);  
  14.  
  15. //set item description  
cat_item.insert()


View solution in original post

3 REPLIES 3

dev_vijaysnowhy
Giga Contributor

hello Ishaan I got this answer from the community itself hope it would be helpful



I've done something similar recently, with new applications being added to the catalog from a script running on the software models table, so when a software model gets signed off, it appears in the catalog automatically.



I've used a Workflow to handle the whole process, with a Script object that actually creates the object.



The concept behind the script is very straightforward:   a gliderecord onto the sc_cat_item table that creates a new record, and sets all the values from the data received by the web service (I don't know enough about web services to answer how you'd achieve that).   If you want to add a set of variables, I suggest you set the required variables up as a variable set, then use another glide record to create an entry on table 'io_set_item', adding the new item to the variable set, adding the variables.



Here are some bits of script that might help..




  1. var cat_item = new GlideRecord('sc_cat_item');  
  2. cat_item.newRecord();  
  3.  
  4. cat_item.name = (current.name);  
  5. cat_item.no_quantity = 'true';  
  6. cat_item.omit_price = 'true';  
  7. cat_item.workflow = 'd1a7905b0fc44ec43276f55be1050eea';  
  8. cat_item.sc_catalogs = '052590b10fabb1003276f55be1050eb5';  
  9. cat_item.owner = (current.owner.name);  
  10. cat_item.u_pid = (current.u_pid);  
  11. //set category to be lowest level defined  
  12.  
  13. //cat_item.price = (current.price);  
  14.  
  15. //set item description  
cat_item.insert()


Hi Vijay,


How can I add variable set through script in catalog item?


Hello ishaan



check is wiki doc below for your exact reference



Creating a Catalog Client Script - ServiceNow Wiki



thank you