Default value for checkbox is displayed undefined

Ujjwal1
Tera Contributor

hi 
i have used checkbox in portal widget. by default value is checked.

 

I am trying to get checkbox value , it is displayed as undefined. Ideally value should be retrieved as  true. Please suggest.

 

screenshot:

   <label><input type="checkbox" name=user_access" ng-model="data.user_access" ng-checked="true"> User Access</label><br/>
//value in client script
 spUtil.addInfoMessage("hi01" + $scope.data.user_access);

Ujjwal1_0-1743670293189.png

 

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Ujjwal1 ,

 

Are you populating the value in the Server Script? If not please add something like this there:

 

data.user_access = true;

 

Then you can change the HTML to this (please note there was also a missing double-quote in the "name" attribute, which is fixed below):

 

<label><input type="checkbox" name="user_access" ng-model="data.user_access">User Access</label>

 

Regards,

Robert

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Ujjwal1 

it means it's unable to get the value.

share the complete widget

Did you initialize the checkbox?

$scope.data = {
    user_access: true
};

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

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

@Ujjwal1 

@Robert H has pointed out the mistake for the missing quote.

That should help you

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

Shivalika
Mega Sage

Hello @Ujjwal1 

 

I can see you have initialized it already. Can you just add "ToString" at the end while getting the data. 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY 

Robert H
Mega Sage

Hello @Ujjwal1 ,

 

Are you populating the value in the Server Script? If not please add something like this there:

 

data.user_access = true;

 

Then you can change the HTML to this (please note there was also a missing double-quote in the "name" attribute, which is fixed below):

 

<label><input type="checkbox" name="user_access" ng-model="data.user_access">User Access</label>

 

Regards,

Robert