Leveraging the Variables functionality in custom tables

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 09:23 PM
We are in the process of planning the design of a Finance module to replace the functionality of the deprecated Finance Service Management plugin.
Where I'm coming up short is how to implement the "variables" field on a custom table (call it "finance_request"), so that Record Producers targeting finance_request can leverage the Variables Related List for questions/answers, in the same way as a "normal" Catalog Item, or one of the "real" Service Management plugin Record Producers (i.e. Finance, Legal, Marketing, etc).
I've noticed that when you create a custom table, the "Variables" field type is not available for use, seemingly making it impossible to implement this functionality on a custom table, without knowing some "trick".
Does anyone know what the criteria is for being able to create fields of the "Variables" type? And/or any documentation on this subject that might be helpful?
Examples below of 2 OOB tables that make use of the Variables field type. This seems to be the main missing ingredient for what we're trying to do. Everything else should be relatively straight-forward(ish).
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 11:10 PM
Hi there,
Not sure if I understand you right. But do you mean something like below, that you want something like that to be available on the form of your custom table?
You could achieve this by looking at the UI Formatters [sys_ui_formatter], and for example, copy the Incident Variable Editor for your own table.
In the form layout, you could then add the Variable Editor.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 02:21 PM
Thanks Mark - that definitely looks like a piece of the puzzle.
What still isn't clear is how you create the Variables field on the table in the first place?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 09:42 PM
Hi there,
Basically, if there are any records associated in the question_answer table or sc_item_option + sc_item_option_mtom table - associated to the record you want to display the variable editor - then this automatically gets available.
These variables are generated for example when using the Standard Change Templates or when submitting a Catalog Item or Record Producer. For example, a Record Producer writes the variables to the question_answer table and associates this to the actual record the Record Producer is for (incident, etc.). The sc_item_option tables are when you're using Catalog Items.
You could also use the variables to your advantage using scripting.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 02:36 PM
Thanks Mark. What is the purpose of the Variables field type then on the tables? e.g. as shown in the screenshots on my original post? (e.g. on sc_req_item).
As an example,
* I create a u_vartest table
* u_vartest has 1 field called u_test which is a String
* I then create a Record Producer called "Tester", target table u_vartest, with 2 variables:
---- "Some Text" - direct field mapping to u_test field
---- "Some Variable" - not a direct field mapping
* Via the Service Portal, I then submit a "Tester", filling in both fields
* A new record is created in u_vartest with the u_test field populated
* ...but, the data entered in "Some Variable" goes... where?
e.g. the following code:
var rs = new GlideRecord("u_vartest");
rs.addQuery("sys_id", "b5e5ceb537103300382b8cf6c3990e2d"); // THE RECORD THAT WAS CREATED
rs.query();
gs.log(rs.getRowCount());
if (rs.next()) {
gs.log(rs.u_test);
gs.log(rs.variables.this_is_a_variable); // THE NAME OF THE VARIABLE
}
/*
OUTPUT:
*** Script: 1
*** Script: steve
*** Script: undefined
*/
I'm fairly sure that not having a "variables" field on u_vartest is the issue - or at least part of it, but ServiceNow doesn't allow you to create a field of that type on custom tables?
Note - sc_item_option & sc_item_option_mtom tables remain empty after the above scenario.