Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

About the client controller for Service Portal widgets

Ro5
Tera Expert

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

1 ACCEPTED SOLUTION

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.

View solution in original post

5 REPLIES 5

Raghav Sharma24
Giga Patron

Can you share the html part?

Also try puttinh alerts to check of you are gettinh anything in the value and share your findings.

 

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

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.

@Ro5 were you able to achieve this?