Business rule help to not include hidden variables

dannyprime
Tera Guru

I have a business rule that when a sc_task is created, all the catalog item variable labels and values are copied in text format into the description field of the sc_task - works well.

The issue I'm having is that it is copying all variables, I want it to not include the hidden variables, so anyone who is able to assist I'd be grateful.

(function executeRule(current, previous /*null when async*/ ) {
    var keys = new Array();
    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item);
    set.load();

    var vs = set.getFlatQuestions();
    var description = '';

    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {						   
            description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
        }
    }
	
    current.description = description;
})
(current, previous);
1 ACCEPTED SOLUTION

vermaamit16
Kilo Patron

Hi @dannyprime 

 

Try with the below script. We need to glide into Item Option table and filter out hidden fields for your requirement.

 

var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var vs = set.getFlatQuestions();
var description = '';
for (var i = 0; i < vs.size(); i++) {
    var grOption = new GlideRecord("item_option_new");
    grOption.get(vs.get(i).getId());
    if (grOption.hidden == false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {
        description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
        gs.info(description);
    }
}

 

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

View solution in original post

4 REPLIES 4

salma98
Tera Contributor

Then you would need to glide into Item Option table and filter out hidden fields.

 

Please mark it as helpful if this helped.

Salma.

vermaamit16
Kilo Patron

Hi @dannyprime 

 

Try with the below script. We need to glide into Item Option table and filter out hidden fields for your requirement.

 

var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var vs = set.getFlatQuestions();
var description = '';
for (var i = 0; i < vs.size(); i++) {
    var grOption = new GlideRecord("item_option_new");
    grOption.get(vs.get(i).getId());
    if (grOption.hidden == false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {
        description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
        gs.info(description);
    }
}

 

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Works great thank you @vermaamit16 😁

Not applicable

@dannyprime To exclude hidden variables from being copied to the description field in your business rule, you can use the isVisible() method from the variable object. This method checks if the variable is set to be visible on the form.