Display Business Rules Equivalent for Widgets on Portals

ZoranG
Tera Contributor

Hello friends! 🙂

 

How would you massage data (on the server side) from a table before handing it over to widgets used on a portal or before sending it as a response from (an out of the box) REST API?

 

On forms, I use display business rules to massage content from a specific table and field before it's sent to the front end. I use this to mask some data on the fly, for example.

 

Unfortunately the display business rules are bypassed by widgets and REST API calls.

 

How can I achieve this for the service portal widgets and the (out of the box) REST APIs? 

 

Modifying the widgets and writing custom scripted APIs to wrap the out of the box rest api would work, but these are terrible solutions. There must be a better and generic way.

4 REPLIES 4

Sunil Mitkari
ServiceNow Employee
ServiceNow Employee

May be you want to create a new field and use before BR to update the value for reading purpose. or you might want to use calculated field type

Thanks Sunil.

 

The output from the display rule varies depending on the user (or a parameter in the API call). For example, for some users, I want to mask all credit card information, for others, I want to mask just the expiry date.

 

If this was a knowledge article, I would want to modify the title of the article for some users, but not to others.

 

I'll explore the calculated field possibility. 

Sunil Mitkari
ServiceNow Employee
ServiceNow Employee

The appropriate solution woulbe writing a before query BR, based on the role of logged in user.
if(gs.getUser().hasRole("")){
currrent.credit_card_number = masked_num;
}

Mark this is helpful if you find!!

Hello Sunil,

 

This won't work. As per the docs, a before query br can modify the query, but won't parse and modify a value that is yet to be retrieved from the db. I also tested this, just in case 🙂

 

ZoranG_0-1731672831723.png

 

So far:

Only a display business rule successfully modifies a field on its way to the user (e.g. in a larger string, mask only the appearance of a credit card number, but leave the rest of the text as is) - but the problem is the display business rules don't run for widgets/api.