How to filter out hidden variables for Service Portal Ticket fields widget?

Laurie Marlowe1
Kilo Sage

Hello,

We have a catalog item that is a record producer.   The catalog item allows the customer to select an application from the CMDB, for which they want assistance.   The Assignment Group (Support Group) is picked up from the application CI.   Everything works fine, EXCEPT on the Service Portal.   The Support Group is a hidden variable that maps to the Assignment Group field on the ticket.   In the Ticket Fields widget, the Support Group is showing along with the other variables.   We do not want the Support Group name to show on the ess view.

I can see in the server code for the Ticket Fields widget where the code is loading the variables.   Is there a way to modify the code so only global variables show, or variables that have a UI Policy or Client Script making them invisible not to be included in the widget?

Line 36 has the $sp.getVariablesArray() code that is getting the variables.   There is nothing in the developer's documentation that describes this method (that I could find).

(function(){

data.pickupMsg = gs.getMessage(options.pickup_msg);

var gr = $sp.getRecord();

if (gr == null)

return;

data.canRead = gr.canRead();

if (!data.canRead)

return;

var agent = "";

var a = $sp.getField(gr, 'assigned_to');

if (a != null)

agent = a.display_value;

var fields = $sp.getFields(gr, 'number,state,priority,sys_created_on');

if (gr.getValue("sys_mod_count") > 0)

fields.push($sp.getField(gr, 'sys_updated_on'));

if (gr.getValue('price') > 0)

fields.push($sp.getField(gr, 'price'));

if (gr.getValue('recurring_price') > 0) {

var rp = $sp.getField(gr, 'recurring_price');

if (gr.isValidField("recurring_price"))

rp.display_value = rp.display_value + " " + gr.getDisplayValue("recurring_frequency");

fields.push(rp);

}

data.tableLabel = gr.getLabel();

data.fields = fields;

data.variables = $sp.getVariablesArray();

data.agent = agent;

data.agentPossible = gr.isValidField("assigned_to");

data.table = gr.getTableName();

data.sys_id = gr.getUniqueValue();

})()

Thank you,

Laurie

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



It will not be possible to change the $sp.getVariablesArray() function.



But you could do a small hack.....You can add a certain text to the label of variables you do not want to display on the service portal. Eg. the if the variable is called "assignment_group" you to rename it to "assignment_group_HIDESP"



Then in the HTML add this between line 38 and 42



              <div class="m-b break-word" ng-repeat="variable in data.variables">


                  <div ng-if="variable.label.indexOf('_HIDESP') == -1">


                            <label class="m-n">{{variable.label}}</label>


                            <div>{{variable.display_value}}</div>


                  </div>


              </div>


View solution in original post

5 REPLIES 5

larstange
Mega Sage

Hi



It will not be possible to change the $sp.getVariablesArray() function.



But you could do a small hack.....You can add a certain text to the label of variables you do not want to display on the service portal. Eg. the if the variable is called "assignment_group" you to rename it to "assignment_group_HIDESP"



Then in the HTML add this between line 38 and 42



              <div class="m-b break-word" ng-repeat="variable in data.variables">


                  <div ng-if="variable.label.indexOf('_HIDESP') == -1">


                            <label class="m-n">{{variable.label}}</label>


                            <div>{{variable.display_value}}</div>


                  </div>


              </div>


Hi Lars,



I like it!   I will keep this in mind, as I think it will be useful.



I did figure out a different way to do what I want without the usage of a hidden variable.   I updated one line of code in the record producer script since u_appl is a reference field:



current.assignment_group = producer.u_appl.support_group;



TAH-DAH!   Then removed the client script that populated the hidden variable.  



Thank you for your speedy, awesome, reply,



Laurie


kente
Tera Guru

A late answer, but i stumbled accross the question when looking for a similar answer 🙂

 

You could also try to play around with the "visible" check marks.

data.variables holds a boolean for visible_guide and visible_summary.
You could uncheck one of them and add a filter to the ng-repeat 

<div class="m-b break-word" ng-repeat="variable in data.variables |filter:{'visible_summary' : 'true'}">

in Approval widget i want to hide html..

 

filter:{visible_summary:true}

tried with this but  not working as expected

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0820434

 

</span>
${Options}
</a>
<div ng-repeat="variable in approval.variables | filter:{visible_summary:true}" ng-if="variable_toggle">
<label class="m-t-xs m-b-none text-muted"><b>{{::variable.label}}</b></label>
<div ng-if="!variable.multi_row"><span class="pre-wrap">{{::variable.display_value}}</span></div>
<div ng-if="variable.multi_row">
<a href="javascript:void(0)" uib-popover-template="'sp_multirow_vs_summarizer.html'" popover-title="{{variable.label}}"
popover-placement="auto right" popover-append-to-body="true" popover-trigger="outsideClick">${Click to view}</a>
</div>
</div>
</div>