The CreatorCon Call for Content is officially open! Get started here.

Get All variable values onChange to a widget

ServiceNow Tech
Tera Contributor

I have a catalog item with 1 custom variable(Service portal widget mapped) and 5 normal variables like single line text.

In the custom variable, I want to show all the remaining filled variable values and whenever any variable value changes, it should auto update in that widget.

For example: My single line text variables hold 'Abc', 'def', 'ghi', 'jkl', 'mno' values in them then my widget should display

Abc, def, ghi, jkl, mno.

If I update ghi to xyz then immediately, widget should show Abc, def, xyz, jkl, mno.\

 

How can i do that?

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@ServiceNow Tech 

what's the business requirement for this?
check this link

Service Portal Widget - grabbing variable value on change in Client Script and passing to Server Scr... 

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

Hi Ankur,

 

Business requirement : We have a custom widget variable at top of the catalog item which shows the summary of all the filled variables on the form.

So whenever a variable is filled, it should get added to summary widget and similarly whenever a value changes it should update in summary widget.

All HTML and CSS stuff for summary widget i have defined already and to show variables, i used ng-repeat. 

Now only thing is how do i pass data to that ng-repeat.

 

@ServiceNow Tech 

did you check the link I shared above?

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

Hi @Ankur Bawiskar 

 

I was able to get that using below script in client controller

 

function($scope) {
         var c = this;
         $scope.$watch(function () {
                   return $scope.page.g_form.getValue('name_of_variable');
         }, function (value) {
         c.data.message = value;
});
}

This script will instantly set the updated value of variable to c.data.message which I can access in html.

This works fine for one variable but I want to make it work for multiple variables. How can I do that? I have the variable names in an array.