Get Multiple Choice Question Choice Text (not Value)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2016 12:33 PM
I am creating a business rule where I am looking at all the multiple choice variables I have on a catalog item. So far I am able to pull the value that is being passed from the multiple choice variable but I really need the text. I am able pull the value by through a glide record on the sc_item_option_mtom table and looking at the sc_item_option.value. This gets me the value of the question choice for the multiple choice text_add but what I need to query off of is the actual Text of the choice "Add Access". Does anyone know how to get this value?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2016 01:01 PM
You can try using get Display Value variable_name.getDisplayValue(); It should take the value and spin it back into the name format. If I'm understanding what you're trying to do correctly.
What does your script look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2016 09:44 AM
Hi Cheyenne,
Here is a portion of my script. I am currently look at the catalog item and searching for any Multiple choice variable values that end with '_remove', which is our standard naming. I would rather and really need to look at the text of the value which should be "Remove Access".
modifySubscriber();
function modifySubscriber() {
var userNAF = current.u_submit_maintenance_for;
var reqItem = current.sys_id;
var creator = current.assigned_to;
var createdBy = current.getDisplayValue('u_verification_assigned_to');
//REMOVE ACCESS
var grVO = new GlideRecord('sc_item_option_mtom');
grVO.addQuery('sc_item_option.value', 'ENDSWITH', '_remove'); //find all values that end with _remove
grVO.addQuery('request_item', reqItem); //only read records for this RITM
grVO.query();
while (grVO.next()) {
var tempMChoice = grVO.sc_item_option.value;//Multiple choice question choice
var grCI = new GlideRecord('cmdb_ci_group');
grCI.addQuery('u_remove_access_name', tempMChoice);
grCI.query(); //Query the group table for the 'Remove Access Name' against the variable value
while (grCI.next()) {
var placeHolder = grCI.getValue('sys_id');
var grSubscribe = new GlideRecord('cmdb_subscriber');
grSubscribe.addQuery('item', placeHolder);
grSubscribe.addQuery('user', userNAF);
grSubscribe.query(); //Query the subscriber table for the AD group and the 'Submit maintenance for' user
if (grSubscribe.next()) {
if (grSubscribe == 'true') {
//If a record already exists but is already set to true, do nothing.
}
else {
//If a record exists but is set to false, set the record back to active
grSubscribe.u_active = 'false';
grSubscribe.u_requested_item = reqItem;
grSubscribe.u_maintenance_completed_by = creator;
grSubscribe.sys_created_by = createdBy;
grSubscribe.update();
}
}
//If no record exists create a record on the subscriber table but set it to false
else if (grCI.name != '') {
var grRemoveFalse = new GlideRecord('cmdb_subscriber');
grRemoveFalse.initialize();
grRemoveFalse.item = placeHolder;
grRemoveFalse.user = userNAF;
grRemoveFalse.u_requested_item = reqItem;
grRemoveFalse.u_maintenance_completed_by = creator;
grRemoveFalse.sys_created_by = createdBy;
grRemoveFalse.u_active = 'false';
grRemoveFalse.insert();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2016 11:00 AM
I think if you try changing this it should display the display name of the variable:
18 grCI.addQuery('u_remove_access_name.name', tempMChoice);
line 42 you might want to add another '='
else if (grCI.name !== '') {