How can I get the price of a question choice for Service Catalog item in a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 12:03 PM
Hello all,
I am having trouble getting the price of a variables question choice in a script. I have a variable named 'selectState' which is of type Select Box. All the question choices are a list of States so the name and value are the same (i.e Text = Alabama, Value = Alabama). Then each question choice has a price (name is: misc) and recurring price (name is: rec_misc). I have tried a few different statements but they have all been returning blank or throw an error (is there a price associated with this item?)
Any help is greatly appreciated!
Thanks in advanced!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 12:50 PM
Hello Favian,
There are two options here. Either to use Scoped API to fetch all the variables and then dot-walking to get the exact variable with its price or the other option is to GlideRecord the table question_choice and then filter the record based on RITM sys_id to fetch the price value.
Sample Scoped API script:
var gr = new sn_sc. CatItem('039c516237b1300054b6a3549dbe5dfc'); //Pass the catalog item sysid here
var x = gr.getVariables();
var myJSON = JSON.stringify(x);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 09:09 AM
Hi Favian, did you get solution to it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 08:49 AM
Hello,
I did manage to figure this out. I was trying to get the price of the item being requested on an approval email just to give you a little background information for the following script. All I had to do was query the 'sc_req_item', pass in the current approval, and that was about it.
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while(gr.next()) {
//...
template.print(gr.price.getLabel() + " = " + gr.price.getDisplayValue() + "\n" );
template.print(gr.recurring_price.getLabel() + " (Annually) = " + gr.recurring_price.getDisplayValue() + "\n" );
}
Please let me know if you have any questions on your specific task you are trying to accomplish. I would be glad to help.