How to update widget when a button is clicked? (how to force the html to udpdate)

juan9
Giga Guru

I have a super simple sample that I would like to update when a button is clicked, below is the table:

 

Screen Shot 2022-11-12 at 12.35.39 AM.png

 

this is the code that populates the table::

```

/*
fetch data that will be displayed on the html on
first render
*/
var gUser = new GlideRecord('sys_user');
gUser.addEncodedQuery('company=81fca4cbac1d55eb355b4b6db0e3c80f');
gUser.orderBy('user_name');
gUser.query();

while( gUser.next() ){
var obj ={};
obj.userID = gUser.getValue('user_name');
obj.name = gUser.getValue('first_name');
obj.email = gUser.getValue('email');
obj.lastName = 'empty';
data.table.list.push(obj);
}

```

 

when the user clicks one of the green buttons, the following client script sends that information to the server script::

```

$scope.showName = function (name){
//alert('The name is : '+name);
c.data.answer = name;
c.server.update()
}

```

 

this is where the issue begins, I want to update the html table, but I cant seem to get this to work!

the code below updates the table that is displayed on the client side. but the widget does not refresh

```

/*
If there is an input, update the data obj with
last name
*/

if (input) {

var gr = new GlideRecord('sys_user');

if(gr.get('user_name', input.answer)){

for ( var row in data.table.list ){

if(data.table.list[row].userID==input.answer) {

data.table.list[row].lasName = gr.getValue('last_name');

gs.addErrorMessage(data.table.list[row].lasName);

}
}
}
}

```

 

 

 

 

 

1 ACCEPTED SOLUTION

Jesalyn S
Kilo Sage

Hi Juan,

 

Is this still an issue? I noticed from the code you posted that the server script

data.table.list[row].lasName = gr.getValue('last_name');

 

has a typo with the lastName property. From this code sample

 

obj.lastName = 'empty';

 

View solution in original post

2 REPLIES 2

Jesalyn S
Kilo Sage

Hi Juan,

 

Is this still an issue? I noticed from the code you posted that the server script

data.table.list[row].lasName = gr.getValue('last_name');

 

has a typo with the lastName property. From this code sample

 

obj.lastName = 'empty';

 

yeah i cought that after posting the question last night.

good eye!