- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 03:48 PM
Hi Andrew,
Yes, that is the goal to get the encoded query to have all the queries. But my encoded wasn't working. I am using the code from another community string and it works perfect but I am needing to filter out some additional fields (I am still learning JavaScript). I see your point about the VARs being inside the other loops but it seems fine and it is how the list of options gets created. I was hoping something would pop-out with my encoded queries not having the correct syntax.
I think that I figure out what I was doing wrong but still doing some testing to validate my changes. When I built the query it was using 'display value' and it looks using 'value' is working now. Also, do you know how I can reduce or clean up this code? All the addQuery's?
var fltr1 = "sc_item_option.item_option_new.nameNOT LIKEu_subscription_users"; // This seems to be working now, using value vs. display value
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request.sys_id);
gr.query();
while(gr.next()) {
// Get Owned Variables for Requested Item and sort by Order
var ownvar = new GlideRecord('sc_item_option_mtom');
ownvar.addEncodedQuery(fltr1); // This seems to be working now
ownvar.addQuery('request_item.number', gr.number);
ownvar.addQuery('sc_item_option.value', '!=', ''); // Doesn't seem to filter anything
ownvar.addQuery('sc_item_option.value', '!=', 'false'); // Removes all 'false' variables (blank)
ownvar.addQuery('sc_item_option.value', '!=', 'undefined'); // Must have this line to work not sure why but when REMARKED out it breaks
ownvar.addNotNullQuery('sc_item_option.value'); // Not sure if this is needed or helping.
ownvar.orderBy('sc_item_option.order');
ownvar.query();
var items = "Summary of " + gr.number + ": " + gr.cat_item.getDisplayValue() + "\n\n";
while(ownvar.next()) {
var field = ownvar.sc_item_option.item_option_new;
var fieldValue = ownvar.sc_item_option.item_option_new.name;
// Print variable name and option value
items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";
}
}
task.description = items;
Thanks!
-Wesley