Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to Run Catalog Client Scripts in Service Portal Widget

Ro5
Tera Expert

hello.
How can I run catalog client scripts in Service Portal widgets?
I wrote the following in the client controller, but it didn't work.

 

var c = this;
c.setTotalAmount = function() {
 // catalog client script
 TotalCalculation();
};

 

Please help me.

Regards,
Ro

1 ACCEPTED SOLUTION

@Ro5 

in the client controller you can access variables of catalog item

Like this

Ensure $scope is set as a parameter in your client controller function as below

api.controller = function($scope) {

//Use the below syntax to access catalog variable value

} 

$scope.page.g_form.getValue('variable_name');

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@Ro5 

is the function TotalCalculation() present inside some catalog client script?

Why to invoke? why not do the calculation in widget only?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

TotalCalculation() does indeed exist in the catalog client script.
I would like to sum some variables in a catalog item.
Where do you do the calculations in the widget?

Regards,
Ro

@Ro5 

in the client controller you can access variables of catalog item

Like this

Ensure $scope is set as a parameter in your client controller function as below

api.controller = function($scope) {

//Use the below syntax to access catalog variable value

} 

$scope.page.g_form.getValue('variable_name');

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ro5 

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
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader