- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 01:14 PM
Hi,
I've got a record producer that creates incident records and I want the variables to display in the ticket description. All good so far, but I don't know how to display the choices when the question is a label type and the answer is a checkbox type value (could be multiple choices). Could someone please help with his, bare in mind I am very new to ServiceNow.
We have this script include:
var addVariableToDescription = function (current, wizardVariable, descriptionText, options) {
options = options ? options : {};
var fieldName = options.fieldName ? options.fieldName : 'description';
var str;
// If the variable passed in was a reference, then use the value of refField from the record it points to.
if (options.refField && wizardVariable[options.refField]) {
str = wizardVariable[options.refField].toString();
} else {
str = wizardVariable.toString();
}
if (str == 'true') {
if (options.dontConvertTrue) {
str = ' ';
} else {
str = 'Yes';
}
}
if (options.convertFalse === true && str == 'false') {
str = 'No';
}
str = str == 'false' ? false : str;
if (str) {
// If a bookingDate option was provided, then reformat the string
if (options.bookingDate) {
str = wizardVariable.getDisplayValue() + ' on ' + options.bookingDate;
}
if (options.convertDate) {
str = wizardVariable.getDisplayValue();
}
if (options.prepend) {
current[fieldName] = descriptionText + str + '\n' + current[fieldName];
} else {
current[fieldName] += '\n' + descriptionText + str;
}
}
};
And this is what I've done so far in the record producer script:
addVariableToDescription(current, producer.department, "\nDepartment: "); //this works fine, the type is multiple choice and displays the value selected
addVariableToDescription(current, producer.reason_for_request, "\nReason for request: "); //type of this is label and the choices are checkbox - multiple choice. I want this to display the value(s) selected but the way it is written now, it only displays 'Yes'
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 01:38 PM
You can loop through all the check boxes with a condition inside the loop to check if the check box is true.
var checkBoxVariables = [];
checkBoxVariables[0] = 'check_box_variable_1';
checkBoxVariables[1] = 'check_box_variable_2';
checkBoxVariables[2] = 'check_box_variable_3';
checkBoxVariables[3] = 'check_box_variable_4';
var checkBoxLabels = [];
checkBoxLabels[0] = 'check_box_label_1';
checkBoxLabels[1] = 'check_box_label_2';
checkBoxLabels[2] = 'check_box_label_3';
checkBoxLabels[3] = 'check_box_label_4';
for(var i=0; i<checkBoxVariables.length; i++) {
if(producer[checkBoxVariables[i]] == 'true') {
current.description += '\n' + checkBoxLabels[i];
}
}
Please mark helpful/correct if this has helped you.
Thanks,
Logan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 01:38 PM
You can loop through all the check boxes with a condition inside the loop to check if the check box is true.
var checkBoxVariables = [];
checkBoxVariables[0] = 'check_box_variable_1';
checkBoxVariables[1] = 'check_box_variable_2';
checkBoxVariables[2] = 'check_box_variable_3';
checkBoxVariables[3] = 'check_box_variable_4';
var checkBoxLabels = [];
checkBoxLabels[0] = 'check_box_label_1';
checkBoxLabels[1] = 'check_box_label_2';
checkBoxLabels[2] = 'check_box_label_3';
checkBoxLabels[3] = 'check_box_label_4';
for(var i=0; i<checkBoxVariables.length; i++) {
if(producer[checkBoxVariables[i]] == 'true') {
current.description += '\n' + checkBoxLabels[i];
}
}
Please mark helpful/correct if this has helped you.
Thanks,
Logan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 01:48 PM
Hi Logan,
I've tried producer.reason_for_request.getDisplayValue() but not only it didn't display the selected choice, it didn't display the question either, it just skipped it basically as I could only see the one for Department.