- 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 08:42 PM
Can you share the html part?
Also try puttinh alerts to check of you are gettinh anything in the value and share your findings.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 10:45 PM
Hi RaghavSh.
I tried setting alerts in several places,
It does not seem to work after the following points.
→var value = g_form.getValue('testset');
Below is the content of the HTML.
<div class="panel panel-default">
<div class="panel-body">
<button type="button" class="btn btn-success btn-block" ng-click="c.setTotalAmount()">calculation</button>
</div>
</div>
Regards,
Ro
- 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-14-2022 04:27 AM
@Ro5 were you able to achieve this?
Raghav
MVP 2023