Set recurring price of choice list in onChange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 10:22 AM
Hello,
I have a select box variable called data_amount
There are options 1, 10, 100, and other.
When other is selected, a text box called other_amount appears where the user can enter a number. When they enter the number here, I want to update the recurring price field on the choice other. Does anyone know how to do that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 10:25 AM
Write an onChange script for the other_amount field so that when it triggers it updates the recurring price field. See below for example:
Or are you talking about grabbing the number and adding it as an option to data_amount?
Please mark as correct/helpful if it resolved your answer!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 10:42 AM
Here is how it looks in the portal. So if I enter 3 in the text box I want to set the recurring price to 3 x 1,159.96
Here is what I tried in an onChange client script. rec_misc is the field for the recurring price on the question choices:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var amount = g_form.getValue('data_amount');
if(amount == 2){ //If other is selected for data amount
var number = newValue;
var cost = (parseInt(number) * '1159.96');
console.log("Cost: " + cost);
var gr = new GlideRecord('question_choice');
gr.addQuery('question', '38c67243dbbcf7c831e0e66505961972'); //Question is Amount of data to be backed up in Terabytes (TB)
gr.addQuery('value', '2');
gr.query();
while (gr.next()) {
gr.rec_misc = cost;
gr.update();
}
}
}
This returns an error in the console saying (GlideRecord) [Q:NOCB] Query must be called with a callback function

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 10:26 AM
For setting Currency via client script there is a great post here
https://community.servicenow.com/people/russ.sarbora/blog/2012/07/20/2543
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2019 10:48 AM
Hi there,
What is the frequency for the recurring price? Is it daily, yearly, etc?
You have create a Recurring Price record to achieve this. Normally done by a checkbox on the Catalog Item, though you'd like this conditionally.
You could create the Recurring Price record simply thru a Business Rule.
Business Rule which checks if it's the Catalog Item of your specification and if the variable other_amount is filled. If true, onAfter or aSync create a record with below script:
If no default Recurring Price:
if(current.variable_pool.other_amount != '') {
var grRecurringPrice = new GlideRecord('sc_recurring_rollup');
grRecurringPrice.initialize();
grRecurringPrice.setValue('recurring_frequency', 'daily');
grRecurringPrice.setValue('recurring_price', current.variable_pool.other_amount);
grRecurringPrice.setValue('request', current.request);
grRecurringPrice.insert();
}
If a default Recurring Price:
if(current.variable_pool.other_amount != '') {
var grRecurringPrice = new GlideRecord('sc_recurring_rollup');
grRecurringPrice.get('request', current.request);
grRecurringPrice.setValue('recurring_price', current.variable_pool.other_amount);
grRecurringPrice.update();
}
Kind records,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field