- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 10:45 PM
How can I multiply 'Unit Price' and 'Quantity' then display it on 'Price' Field and then display the sum in 'total cost'.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2022 06:20 AM
Hi
You can follow the community reply by
Please find step by step solution below:
- Create a Widget and add the below-provided script:
api.controller = function($scope) { /* widget controller */ var c = this; $scope.$watch(function() { //Internal Name of Variable Set 'item_details' return $scope.page.g_form.getValue('item_details'); }, function(value) { if (value) { var mrvsData = JSON.parse(value.replace(/'/g, '')); console.log(value); var totalCost = 0; for (var i = 0; i < mrvsData.length; i++) { var mrvs = mrvsData[i]; totalCost += parseInt(mrvs.price); alert('Calculating: ' + totalCost + ' for --> ' + mrvs.price); } //Set Value in the Total Cost alert(totalCost); $scope.page.g_form.setValue('total_cost', totalCost); } }); };
- Create a Variable of type Custom and add the Widget created in Step 1
- Variable details are provided below:
- item_details: Internal Name of the MRVS Variable Set
- total_cost: Variable on the Catalog Item (not inside MRVS variable Set)
Please follow the above steps and import the Update set provided in the attachment.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 11:13 PM
Hi,
you can observer the Add button and based on that populate the value
OR
you can use onSubmit catalog client script on the Catalog Item
1) get the mrvs json
2) parse it
3) calculate and set the Total cost
Solution shared by me here
Calculating totals from mult-row variable set rows in to a variable on a record producer?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:05 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 08:54 PM
Did you mistakenly marked other response as correct?
The answer marked as correct has the link which I already shared first.
You can mark only 1 response as correct.
Please mark appropriate response as correct based on timely response.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2022 06:20 AM
Hi
You can follow the community reply by
Please find step by step solution below:
- Create a Widget and add the below-provided script:
api.controller = function($scope) { /* widget controller */ var c = this; $scope.$watch(function() { //Internal Name of Variable Set 'item_details' return $scope.page.g_form.getValue('item_details'); }, function(value) { if (value) { var mrvsData = JSON.parse(value.replace(/'/g, '')); console.log(value); var totalCost = 0; for (var i = 0; i < mrvsData.length; i++) { var mrvs = mrvsData[i]; totalCost += parseInt(mrvs.price); alert('Calculating: ' + totalCost + ' for --> ' + mrvs.price); } //Set Value in the Total Cost alert(totalCost); $scope.page.g_form.setValue('total_cost', totalCost); } }); };
- Create a Variable of type Custom and add the Widget created in Step 1
- Variable details are provided below:
- item_details: Internal Name of the MRVS Variable Set
- total_cost: Variable on the Catalog Item (not inside MRVS variable Set)
Please follow the above steps and import the Update set provided in the attachment.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 09:58 PM
Hi
Did you get a chance to check the reply provided by me?
If yes and if my answer helped you out then please mark my answer as correct/helpful, so that other community members facing similar issues might get help.
Thanks and regards,
Kartik