How to populate checkboxes on the catalog form on serviceportal

ChaitanyaM72564
Tera Contributor

How to get checkboxes checked once they raised form after one year they have to raise again then existing fileds and check boxes check should populate automatically in the catalog form. I used script include and client script it’s not working.ow

4 REPLIES 4

Brad Bowman
Kilo Patron

Post the scripts using the insert code icon </> and we'll get it sorted. 

ChaitanyaM72564
Tera Contributor

Scripts include-

var GetLastInternetException = Class.create();
GetLastInternetException.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getLastRequest: function () {

var userId = gs.getUserID();
var result = {};

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('requested_for', userId);
ritm.addQuery('cat_item.name', 'Internet Exception'); // exact catalog item name
ritm.orderByDesc('sys_created_on');
ritm.setLimit(1);
ritm.query();

if (ritm.next()) {

result.facebook = ritm.variables.facebook == 'true';
result.twitter = ritm.variables.twitter == 'true';
result.google = ritm.variables.google == 'true';

result.short_description = ritm.variables.short_description.toString();
result.access_required = ritm.variables.access_required.toString();
result.business_director = ritm.variables.business_director.toString();
}

return JSON.stringify(result);
}
});

 

Clientscript- 

function onLoad() {

var ga = new GlideAjax('GetLastInternetException');
ga.addParam('sysparm_name', 'getLastRequest');

ga.getXMLAnswer(function(response) {

if (!response) return;

var data = JSON.parse(response);

// Checkboxes
g_form.setValue('facebook', data.facebook);
g_form.setValue('twitter', data.twitter);
g_form.setValue('google', data.google);

// Single line text fields
g_form.setValue('short_description', data.short_description);
g_form.setValue('access_required', data.access_required);
g_form.setValue('business_director', data.business_director);

g_form.addInfoMessage(
'Previous Internet Exception details have been auto-filled.'
);
});
}

 

Text fields it’s working but checkbox not working. please help me on this part.

 

ChaitanyaM72564
Tera Contributor

Hi @Brad Bowman  

 

Script include-

var GetLastInternetException = Class.create();
GetLastInternetException.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getLastRequest: function () {

var userId = gs.getUserID();
var result = {};

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('requested_for', userId);
ritm.addQuery('cat_item.name', 'Internet Exception'); // exact catalog item name
ritm.orderByDesc('sys_created_on');
ritm.setLimit(1);
ritm.query();

if (ritm.next()) {

result.facebook = ritm.variables.facebook == 'true';
result.twitter = ritm.variables.twitter == 'true';
result.google = ritm.variables.google == 'true';

result.short_description = ritm.variables.short_description.toString();
result.access_required = ritm.variables.access_required.toString();
result.business_director = ritm.variables.business_director.toString();
}

return JSON.stringify(result);
}
});

 

Client script -

function onLoad() {

var ga = new GlideAjax('GetLastInternetException');
ga.addParam('sysparm_name', 'getLastRequest');

ga.getXMLAnswer(function(response) {

if (!response) return;

var data = JSON.parse(response);

// Checkboxes
g_form.setValue('facebook', data.facebook);
g_form.setValue('twitter', data.twitter);
g_form.setValue('google', data.google);

// Single line text fields
g_form.setValue('short_description', data.short_description);
g_form.setValue('access_required', data.access_required);
g_form.setValue('business_director', data.business_director);

g_form.addInfoMessage(
'Previous Internet Exception details have been auto-filled.'
);
});
}

Brad Bowman
Kilo Patron

I would try this in the SI, and if it doesn't work add a log to the SI to see what the value of ritm.variables.facebook is and set the result.facebook value to 'true' or 'false' accordingly.

result.facebook = ritm.variables.facebook.toString();
result.twitter = ritm.variables.twitter.toString();
result.google = ritm.variables.google.toString();

I'm not sure off the top of my head if checkboxes are 'true' or 'false' or boolean true/false when retrieving and setting the value, so you might need to convert the setValue to boolean.