- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 01:25 PM - edited 04-22-2024 01:56 PM
Hi folks,
I have seen this question asked on the community, but nothing seems to fit my particular situation. I have inherited a catalog item request form with a list collector where users can select multiple Adobe products to request. The reference for the list collector is the sys_user_group table. I cannot see any pricing info on it or any related fields. I have the following client script which contains an associative array for the pricing, and I am trying to loop through the user selections; look up the prices in the associative array; sum up the prices for all the selected items and update the catalog item price with the total.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Calculates the total price of the selected Adobe products
var priceArray = [{"AdobeEnt.AdobeCCE.AcrobatPro": 127.44, "AdobeEnt.AdobeCCE.AfterEffects": 381.60, "AdobeEnt.AdobeCCE.Audition": 381.60, "AdobeEnt.AdobeCCE.Dreamweaver": 381.60, "AdobeEnt.AdobeCCE.FullSuite": 835.44, "AdobeEnt.AdobeCCE.Photoshop": 381.60, "AdobeEnt.AdobeCCE.Premiere": 381.60, "AdobeEnt.AdobeCCE.Stock": 381.60}];
var adobeApps = g_form.getValue('which_product_are_you_requesting');
var apps = adobeApps.split(',');
var total = 0;
for (var i=0; i<apps.length; i++) {
if (priceArray.get(apps[i])) {
total += priceArray.get(apps[i])[1];
}
}
return total;
g_form.setValue('price', total);
}
I am not sure if it is my array, loop or something else, but the price is not being set when I test out the form and always coming back as $0.00. As always, any help is greatly appreciated.
Thanks,
Ken
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:30 PM
@Ken Berger in client script on change of total_price field is selected change it to onchange of "which_product_are_you_requesting" then it should work.
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 11:39 PM
Hi @Ken Berger yeah sure, you can update the existing display business rule as below,
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
if (gr.next()) {
var totalPrice = gr.variables.price;
current.price = totalPrice;
gr.price = totalPrice;
gr.update();
}
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 06:38 AM
That is working. Thank you again!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday - last edited Tuesday
Depending on what you do, this solution here can have undesired consequences.
The issues I see:
- you are not using the model - this can become important for things like Financial Management
- gr as a variable name is a taboo (a bit like current)
So while this might work for your current requirements, keep in mind that you have potential technical debt to pay later.
If this post was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel