Populate the Multiline Text field value based on the checkbox selected in Catalog Item

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:49 AM
Hi SNOW Champs, I have a requirement where the Multiline Text in the Catalog Item should be populated based on the checkboxes selected. Example, I have three checkboxes, so whenever I select any of the checkboxes or maybe multiple, than the checkbox label should appear in the multi-line text field in separate lines i.e. single checkbox label in each line. I am certain that this can be achieved via On Submit client script but not sure about the script which needs to be used. Can someone help on the script please.
Example:
Checkbox 1 - Selected
Checkbox 2 - Selected
Checkbox 3
Multi-line Text field should populate as below :
Checkbox 1 label
Checkbox 2 label
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 06:43 AM
Since you know what the labels are, and they don't change we can keep this simple. If you want to use this for multiple items you can call a script include to lookup the variable labels and return that to the text box.
function onSubmit() {
var mytxt = '';
if(g_form.getValue('v_my_checkbox1') == 'true' ){
mytxt = 'Checkbox 1 label';
}
if(g_form.getValue('v_my_checkbox2') == 'true' ){
if(mytxt == ''){
mytxt = 'Checkbox 2 label';
}
else{
mytxt = mytxt + '\nCheckbox 2 label';
}
}
if(g_form.getValue('v_my_checkbox3') == 'true' ){
if(mytxt == ''){
mytxt = 'Checkbox 3 label';
}
else{
mytxt = mytxt + '\nCheckbox 3 label';
}
}
g_form.setValue('v_text', mytxt);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2019 09:37 AM
Hi Brad, Thanks for reply.
Is it possible to achieve this via on-change client script ? Client requires the value in the multi line field to populate on real time basis. So, when a checkbox 1 is checked, it displays in multiline text field and if unchecked it no longer shows in text field. Similiarly for checkbox 2 and 3 also. Each checkbox label should populate to a new line in multiline text field. I am not able to achieve this basically so how can we remove a specific line from the multi line text based on the checkboxes. Also not sure how can we assign each checkbox label to the next preceeding line?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 05:24 AM
Same script, just create one onChange for each checkbox variable:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var mytxt = '';
if(g_form.getValue('v_my_checkbox1') == 'true' ){
mytxt = 'Checkbox 1 label';
}
if(g_form.getValue('v_my_checkbox2') == 'true' ){
if(mytxt == ''){
mytxt = 'Checkbox 2 label';
}
else{
mytxt = mytxt + '\nCheckbox 2 label';
}
}
if(g_form.getValue('v_my_checkbox3') == 'true' ){
if(mytxt == ''){
mytxt = 'Checkbox 3 label';
}
else{
mytxt = mytxt + '\nCheckbox 3 label';
}
}
g_form.setValue('v_text', mytxt);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 02:41 PM
Hello Brad,
Even I am writing a script to achieve a similar condition. It is not for a "check-box" but for a variable selected . I have created a Catalog UI policy but also it is failing. Below is my client script can you please suggest what needs to be modified.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert('test Mount_info');
var server_sys_id = g_form.getValue('ServerCI');
alert('hello');
var ga = new GlideAjax('fmr_add_backup_FS');
ga.addParam('sysparm_name', 'validateRequestDetails');
ga.addParam('sysparm_tvm', server_sys_id);
ga.getXML(getResponse);
function getResponse(response) {
var fsDetail = response.responseXML.documentElement.getAttribute('answer');
alert(fsDetail);
if (complete-partial == 'Partial'){
g_form.setValue('File_System_detail', fsDetail);
}
}
}