- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 06:00 PM
hello.
I have a question about the Service Portal widget.
I want to create a new button type widget and when the button is clicked I want to get the value of the catalog item variable set and calculate the sum and display it in another variable field.
Therefore, I wrote the following script in the client controller of the newly created widget, but it did not work well.
api.controller=function($scope) {
/* widget controller */
var c = this;
c.setTotalAmount = function() {
var g_form = $scope.page.g_form;
var value = g_form.getValue('testset');
if (value) {
var mrvsData = JSON.parse(value.replace(/'/g, ''));
for (var i = 0; i < mrvsData.length; i++) {
var mrvs = mrvsData[i];
// get quantity
quantity = g_form.getValue(mrvs.name);
// calculate
total += parseInt(mrvs.price * quantity);
}
}
//Set Value in the Total Cost
g_form.setValue('total_price', total);
};
};
I would like to know if anyone knows where I am going wrong.
Regards,
Ro
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 10:54 PM
Can tou tre below:
var g_form = $scope.page.g_form; // remove this line
var value =$scope.page.g_form.getValue('testset'); // try this directly and alert value to check if you get the value of your variable.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 10:55 PM - edited ‎11-13-2022 10:56 PM
hello @Ro5 are you sure that you are using the correct MVRS internal name ?
try double checking the internal name once
Also replace your JSON.parse line to below
var mrvsData = JSON.parse(value);