- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:20 AM
Hi Everyone,
I have an requirement that, I need to send the data from server side to HTML check box. Based on server side data, i need to show the checkbox field either true or false. I have tried with using below data and unable to fetch and show the data in service portal. Please check below code and correct me.
HTML Code:
<div >
<label><input type="checkbox" ng-model="chkbx" ng-checked="data.u_customfield" ng-click="checkNotify(chkbx)" ng-checked="false"> testing</label>
</div>
Server side:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 01:28 AM
Hi @suresh91
This should work:
HTML:
<div >
<label><input type="checkbox" ng-model="chkbx" ng-checked="data.u_customfield" ng-click="c.checkNotify(chkbx)"> testing</label>
</div>
Client:
api.controller=function($scope) {
/* widget controller */
var c = this;
c.checkNotify = function(val) {
c.data.action = "getField";
c.data.value = val;
alert("test Before " + val);
c.server.update().then(function(response){
alert("test After " + response.u_customfield);
})
}
}
Server:
(function() {
if (input){
if (input.action == "getField"){
var gr_notify = new GlideRecord('sys_user');
gr_notify.addQuery('sys_id', gs.getUserID());
gr_notify.query();
if(gr_notify.next())
{
gs.addInfoMessage(gr_notify.getDisplayValue())
data.u_customfield = gr_notify.u_customfield;
return data;
}
}
}
})();
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:46 AM
Hi Dutta,
Thanks for your response.
I did the change but still not getting value. I tried to add info message like below and it showing value in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 01:06 AM
Hi @suresh91
Can you try declaring variable outside if condition like below :
/*Declare variable here*/
var u_customfield;
var gr_notify = new GlideRecord('sys_user');
gr_notify.addQuery('sys_id', gs.getUserID());
gr_notify.query();
if(gr_notify.next())
{
/*initialize here*/
u_customfield = gr_notify.u_customfield;
}
data.u_customfield = u_customfield;
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 01:14 AM
Hi Vishal,
Thanks for your response.
I tried the above one but still not showing data value.