How to set check box value default as true when page loads
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 10:13 PM
HI
We have a maintain item in which we have a variable set.
There are multiple checkboxes available. In that i need Desktop variable set to default as true. It is checkbox type.
I tried using true in default value as true in that variable, but it is not working.
There are few more checkboxes for which default value is not set as true, but they are working by default as true.
Please help me to fix this issue.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 11:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 10:34 PM
Hi,
ideally it should work with default value
If not then use onLoad client script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 12:12 AM
Hi
I have set the default value to true in desktop variable. its working on servicenow legacy.
But in portal view, its not showing up.
Any idea or workground to fix the issue Ankur. Please help me.
I could see that, one catalog client script onchange as below.
function onChange(control, oldValue, newValue, isLoading) {
var variables = ['u_thin_client', 'u_desktop', 'u_laptop', 'u_docking_station', 'u_monitor', 'u_second_monitor', 'u_mouse', 'keyboard', 'wired_headset', 'u_ethernet_cable', 'u_speakers', 'u_webcam'];
for (var i = 0; i < variables.length; i++) {
clear(variables[i]);
}
g_form.getReference('requester', setDept);
}
function setDept(user) {
var dept = user.department;
var ga = new GlideAjax('UserInfoHelper'); // the Script Include object name
ga.addParam('sysparm_name', 'getCostCenterBundle'); // the function on the server to call
ga.addParam('sysparm_theid', dept);
ga.getXML(callMe);
}
function callMe(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer); //JSON String
//answer = answer.evalJSON(); //This line is no longer supported on CSM portal
answer = JSON.parse(answer); //Transform the JSON string to an object
if (answer.u_thin_client) g_form.setValue('thin_client', answer.u_thin_client);
if (answer.u_desktop) g_form.setValue('desktop', answer.u_desktop);
if (answer.u_laptop) g_form.setValue('laptop', answer.u_laptop);
if (answer.u_docking_station) g_form.setValue('docking_station', answer.u_docking_station);
if (answer.u_monitor) g_form.setValue('monitor', answer.u_monitor);
if (answer.u_second_monitor) g_form.setValue('monitor2', answer.u_second_monitor);
if (answer.u_mouse) g_form.setValue('mouse', answer.u_mouse);
if (answer.u_keyboard) g_form.setValue('keyboard', answer.u_keyboard);
if (answer.u_wired_headset) g_form.setValue('wired_headset', answer.u_wired_headset);
if (answer.u_ethernet_cable) g_form.setValue('ethernet_Cable', answer.u_ethernet_cable);
if (answer.u_speakers) g_form.setValue('speakers', answer.u_speakers);
if (answer.u_webcam) g_form.setValue('WebCam', answer.u_webcam);
}
function clear(item) {
g_form.setValue(item, '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 12:32 AM
Hi,
is UI type - ALL for your client script?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 12:37 AM
HI Ankur,
Yes it shows ALL.
There is a SI for this Client script.
var UserInfoHelper = Class.create();
UserInfoHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData : function(){
var obj = {};
var response;
var theID = this.getParameter("sysparm_theid");
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", theID);
gr.query();
if (gr.next()){
/* this code puts single elements into an object
gs.log("logging location " + gr.location.getDisplayValue(), "bat");
obj.location = gr.location.getDisplayValue();
obj.phone = "test";
obj.email = "test";
response = new JSON().encode(obj);
* the code below puts then entire record into an object */
var g = new JSONGR();
var t = g.encodeGr(gr);
return t;
}
},
getCostCenter : function(){
var ID = this.getParameter("sysparm_theid");
var gr = new GlideRecord('cmn_department');
gr.addQuery('sys_id',ID);
gr.query();
if(gr.next()){
var g = new JSONGR();
var t = g.encodeGr(gr);
return t;
}
},
getApprovalPath : function(){
var ID = this.getParameter("sysparm_theid");
var gr = new GlideRecord('u_requisition_approval_path');
gr.addQuery('sys_id',ID);
gr.query();
if(gr.next()){
var g = new JSONGR();
var t = g.encodeGr(gr);
return t;
}
},
getCostCenterBundle : function(){
var ID = this.getParameter("sysparm_theid");
var gr = new GlideRecord('cmn_department');
gr.get(ID);
return _getbundle(gr.u_telecommute_package);
},
type: 'UserInfoHelper'
});
function _getbundle(id){
var gr = new GlideRecord('u_telecommute_packages');
gr.get(id);
var g = new JSONGR();
var t = g.encodeGr(gr);
return t;
}