Displaying variables on a back‐end HR case form - jcmings/sn GitHub Wiki

Variables

If you've ever submitted a catalog item or record producer in ServiceNow, you're probably familiar with variables. If not... variables are the fields that you fill out prior to hitting Submit. It's where you capture your name, your request, or whatever.

Here's an example, for the visual people: image

The two options under Optional Software are both variables. As is the free-text field underneath the label Additional software requirements. These three fields--variables--are passed along as part of your final request.

Getting variables to display on ITSM-related records

To get them to display in the back-end, you just have to pull the Variable Editor item over in your Configure > Form Layout, like so:

image

And then you'll see them display on your back-end case form:

image

But what about HRSD?

But what about HRSD...? Great question. I don't see an option to pull in Variable Editor onto my HR case forms. Maybe it's different in your instance... but it certainly wasn't there in mine. (The screenshots above come from the Requested Item [sc_req_item] form on my PDI.)

So how can we get variables to display? It's actually pretty simple, and it's a three-step process.

Creating a UI Macro

I'm not going to lie. I don't really know much about UI Macros. And I definitely don't know much about Jelly code. But this worked when I borrowed inspiration from another UI Macro, so here we go. You're going to head over to System UI > UI Macros and create a new one. It should look like this:

image

You can name it whatever you want, and the API Name will automatically populate. Since I'm doing this on the base HR Case [sn_hr_core_case] table, I'm in the Human Resources: Core scope. Feel free to add a description, and copy the below code into the XML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:inline template="com_glideapp_questionset_default_question_editor" />
</j:jelly>

Next step: creating a UI Formatter

Now that you've done that, you can create a UI Formatter. Go to System UI > Formatters and create a new record like below:

image

Whatever you choose for your Name is what you'll see when you are in Configure > Form Layout. In the Formatter box, paste in the API Name from the UI Macro. Choose your table and leave everything else as is. Seismic Component? I have absolutely no clue what that is. So leave it blank.

Optional step: create an on-load client script to make your variables read-only

If you want to set your variables as read-only, you can do so in an onLoad Client Script. The most important thing to remember when creating your client script is to choose the correct Table. If you want this to work on HR Workforce Administration Cases [sn_hr_core_case_workforce_admin], you need to choose that as your table. If you choose HR Case [sn_hr_core_case], the client script will not run.

The second most important thing to remember is to set the Order of your client script to a high value. This way, you can ensure it is triggered.

My client script is pretty basic, and only includes a singular function: g_form.setVariablesReadOnly(true);:

image

If you want, you can add different criteria. For example, you could set the variables read only if the case's state is a certain value. Just remember that you have to use g_form to get the value, since this is a client script after all.

Add it to your Form Layout

This should be implied... but you need to add this to your back-end form's Form Layout to get it to actually dipslay.

Hope this helped you!

⚠️ **GitHub.com Fallback** ⚠️