Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to reference multiple tables in one field using scripted reference qualifier?

sambhogal
Kilo Contributor

Happy New Year Folks!!

I want to be able to reference multiple tables in a field (named 'Target', reference type field) based on the value of another field (named 'Type').

For e.g.

when 'Type' = 'Service Offering', field 'Target' should reference 'service_offering' table;

when 'Type' = 'Configuration Item', field 'Target' should reference 'cmdb_ci' table etc.

How can this be achieved? Thanks for your help!

6 REPLIES 6

paulmorris
Giga Sage

OOB Service Offering extends Business Service, which extends the CI table. CI is the base table of both,


Make your field a reference field of CI and your requirement is achievable.


You can add other exclusions to the [if true] section for your other tables.



//[Boolean condition ? [if true] : [if false];


//If you select a type of CMDB, it shows all CI's except service offerings


//If you select a type of Service Offing, it only shows SO's


javascript: (current.getValue('type')=='cmdb_ci') ? "sys_class_name!=service_offering":"sys_class_name!="current.getValue('type');



You could put the code above in a more readable "best practice" form in a script include if you wanted.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

BrianD502676804
Kilo Sage

Hi Simranjit,



From your requirements, it sounds like you would need to use a Document ID field type.   It can reference any record in any table, and actually exists as two fields (one to store the table and the other the record sys_id).



Please see here in the wiki:


Creating a Document ID Field - ServiceNow Wiki



Hopefully that helps.




Thanks,


-Brian