Service Catalog Service Portal. Triggering price recalculation.

robertyoung
Giga Contributor

So I've been trying for a while to add a custom component to catalog items to do a quantity in service portal. Not an item quantity, an option quantity.

 

Our console solution was to have a lookup select box on the catalog items that pointed to a custom table that held prices we could manipulate. We would then flip that select box from the value with the price to "" and back to the value which would trigger a price re-calculation. Doing that in script does not trigger the price calculation. We've found that by doing it in a setTimeout it will but the time varies. Clearly we don't want to rely on that.

 

What i would REALLY like to do is to modify the catalog widget to add a record watcher for our custom price table and have that record watcher trigger a price re-calculation but I can't figure out for the life of me how to do a "calcPrice" in service portal. (It doesn't appear to be available anymore in console either in kingston)

 

Does anyone out there know how to trigger price recalculation in a way that works in portal? bonus points if it also works in console.

 

Edit: Found another person with the same basic issue, no answer: https://community.servicenow.com/community?id=community_question&sys_id=4fdacb6ddb5cdbc01dcaf3231f96197e

10 REPLIES 10

Ok more specifically, what is happening with us is when the price values in the custom table are changing it's not triggering a price recalculation. We are having to do a setValue in the same script to flip the variable referencing the custom table from "" to the value again so it'll trigger price calculation. Does a reference variable work differently than a lookup select variable?

 

That setValue in portal does not trigger the re-calculation on the screen for the user. it's "too fast" or something. (We are executing it at the end of the onChange script on the quantity boxes)

Yes. I remember doing giving user an option to select a checkbox. If they select the checkbox, it will do that calculation and then create a new Price Record and associate it to the catalog. And then ti automatically unchecks the checkbox. If user again check the checkbox, it will do the recalculation and create a new Price Record and associate the new record to the catalog

 


Please mark this response as correct or helpful if it assisted you with your question.

Yep, that puts us in the same place. The ask for this question is... can it be done without the user having to check a box.

 

In console you can "flip" the reference field from "" back to it's appropriate value with something like:

 

g_form.setValue("dynamicprice","");
g_form.setValue("dynamicprice",theSysID);

 

That works great in console and is what we've used for a long time, doesn't work at all in portal.

Can you add an alert, just to check if it runs this code?

 

g_form.setValue("dynamicprice","");

alert(theSysID);
g_form.setValue("dynamicprice",theSysID);


Please mark this response as correct or helpful if it assisted you with your question.

Yes, it definitely runs the code. Portal is weird. You can actually SEE the drop down flip (it would be hidden in a real servuce but we've got it exposed for this service)

you can tell it's not working properly though. We use the system property to show what the select boxes effect will be on the price and the little values telling you how much will be added never clear out if you do it with the client script like that.

 

You CAN do a setTimeout and wait some number of seconds to then set it back to the actual value BUT that value varies. It doesn't consistently work every time at say 1 second so it's not just a matter of waiting for the page to return control to your javascript scope. Something else is going on. Like if you flip it too quick events on the portal widget aren't firing.

 

This guy had the same issue basically, with no answers.

 

https://community.servicenow.com/community?id=community_question&sys_id=4fdacb6ddb5cdbc01dcaf3231f96197e