How can I selectively display variables on the Service Portal Ticket F

https://community.servicenow.com/thread/246524



The default script does a loop on data.variables, which is retrieved via:

 

  1. data.variables = $sp.getVariablesArray();  

 

Now I don't know whether the getVariablesArray function gets all of the fields for the variables, but if it does then you could simply use ng-if to only display what you want:

        <div class="m-b break-word" ng-repeat="variable in data.variables">  
          <div ng-if="variable.item_option_new">  
               <label class="m-n">{{variable.label}}</label>  
               <div>{{variable.display_value}}</div>  
          </div>  
        </div>

 

Alternatively you could use ArrayUtil to remove the desired fields from the array via indexOf and splice, though I haven't tried this before. Something like this:

 

How to splice an array out of a nested array - javascript - Stack Overflow

 

You could take a look at the structure of the array using:

  1. console.table(data.variables);  

Which will print out the whole array to your browser console.