Leveraging the Variables functionality in custom tables

stevejarman
Giga Guru

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).

find_real_file.png

 

find_real_file.png

 

find_real_file.png

10 REPLIES 10

Mark Roethof
Tera Patron
Tera Patron

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?

find_real_file.png

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.

find_real_file.png

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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?

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

LinkedIn

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.

find_real_file.png

 

find_real_file.png

 

find_real_file.png