How to make a business rule run ONLY on service portal?

Smith Johnson
Tera Guru

Hello,

 

I have a before query business rule on incident table.

I want the script to run ONLY when the user sees the incidents on a table on service portal.

The script of the business rule SHOULD NOT run when the user sees incidents on backend.

How can I make this?

 

Thank you.

1 ACCEPTED SOLUTION

Hi,

Can you add that in the script section?

if that doesn't work then use this

gs.action.getGlideURI().toString().indexOf('csm') > -1

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

in the BR condition add this so that it runs only for portal

if(GlideTransaction.get().getRequest().getHeader("referer").indexOf('sp') > -1)

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Hey Ankur,

should I replace the 'sp' with my portal prefix?

GlideTransaction.get().getRequest().getHeader("referer") will return the full string of the URL that caused the query to be initiated, so if your portal prefix is /xyz then you would want look for indexOf('xyz') > -1

If you wanted this to be limited to a specific page, you can also include the id parameter: 

if(GlideTransaction.get().getRequest().getHeader("referer").indexOf('xyz?id=my_requests') > -1);

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

@Smith Johnson 

that's correct.

use your portal prefix

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader