How to Make Variables Read Only Using g_form in ServiceNow

Variables Read Only

I was recently working with a colleague who mentioned that he had seen a new (un-documented) g_form method which allows you to set all catalog item Variables to Read Only. As you can probably imagine, this is great news for all ServiceNow developers who in the past had to resort to DOM manipulation, custom Business Rules or lots of UI Policies (thanks to my mentor Mark Stanger for providing information on these options in the past) just perform this trick (makes it so fulfillers of tasks update variables but they can’t be updated from the catalog item request). Without further waiting; here’s the magic:


4 thoughts on “How to Make Variables Read Only Using g_form in ServiceNow”

  1. This would have been so handy to have a couple of months ago! I ended up using a Business Rule to query the variable pool and stored all of my variables in the scratchpad. Then an onLoad client script uses that to make all of the variables read only. No DOM manipulation, but definitely more work than your one liner.

    Thanks for sharing!

    1. Hi Robert,

      Yeah that is definitely a better alternative to the DOM manipulation route; I’m with you though, I wish ServiceNow would publish this method!

  2. There is a reason it’s undocumented, it has issues setting some variables readonly in variable sets. At least that’s our experience. Back to ondisplay business rule, scratchpad and a ui policy…

    1. Good to know; yeah sometimes the longest ways are the most effective… I am curious to know which variable types you’ve seen issues with though; please do share!

Leave a Reply

Your email address will not be published. Required fields are marked *