GlideappVariablePoolQuestionSet - Possible to filter based on a true/false field on the variable?

jlaps
Kilo Sage

I need to include a couple variables on notifications. I am having trouble finding information on 

GlideappVariablePoolQuestionSet so am trying to ask here. I created a field on the variable table, true/false, and I want to use this method to include non-empty (which already works on my email script), but include a line to filter only those variables marked "include = true". Can that be done on this sort of email script, referencing fields on the variables from within this method? Is the syntax same as always, or different from within this?
 
 

 

var set = new GlideappVariablePoolQuestionSet();

        set.setRequestID(item.sys_id);
        set.setTaskID(current.sys_id);
        set.load();

        var vs = set.getFlatQuestions();
if(vs.size() == '0' || vs.size() == '')
2 REPLIES 2

jlaps
Kilo Sage

Struggling to get this working according to the requirements. Got closer with the function

if (!vs.get(i).isVisibleSummary()), but the problem using that is that some requests have a large number of variables and the notification looks terrible this way. Also, if I remove the visible on summary flag from all but a few, well some of those variables are useful to have on the Variable Summarizer on the portal, so I need to be able to only show the variables that are flagged to show on notifications probably using a new field on the variable (include on approvals = true).
 
My question is how to generate and use this smaller variable list using GlideappVariablePoolQuestionSet?
Current code-

 

(function runMailScript(current, template, email, email_action, event) {

    var item = new GlideRecord("sc_req_item");
    item.addQuery("sys_id", current.sysapproval);
    item.query();
    while (item.next()) {
        
 var keys = new Array();
        var set = new GlideappVariablePoolQuestionSet();

        set.setRequestID(item.sys_id);
        set.load();

        var vs = set.getFlatQuestions();
if(vs.size() == '0' || vs.size() == '')
{
return;
}
else
{
		//template.print("<hr style='width: 98%;' /><p><b><u>Approval Details</u></b></p>");
		
          for (var i = 0; i < vs.size(); i++) {
			if (!vs.get(i).isVisibleSummary()) {
			continue;}
            if (vs.getLabel() != "" && vs.getDisplayValue() != "" && vs.getDisplayValue() != 'false' && vs.get(i).getDisplayValue() != 'false' && vs.get(i).getDisplayValue() != '') {
                template.print("<p><b>" + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "</p>");

            }
        }
    }

}
})(current, template, email, email_action, event);

 

From my searching, using an onSubmit catalog client script would be unreliable to write to a field on the RITM as the RITM is busy being created onSubmit. I think I could use an after insert business rule perhaps to capture variables flagged as include=true? Since the LABEL is available in the GlideappVariablePoolQuestionSet, I can populate an array with the include = true variable.label and add that to the IF check on the email script? 

How would that look, or is there a better option?

SarendrilaB4791
Tera Contributor

Hi jlaps,

Did you get any solution for this issue. I'm facing similar issue, causing slowness due to use of custom field to show / hide variable in the generic notifications.