How to check if a reference field in macro type variable is filled using a client script.


This article explains how check whether a reference field in UI macro type variable is filled so that variable mandatory can be enforced on submission using a onSubmit client script.


The catalog variable UI macro can be something like:

<g:ui_reference name="QUERY:active=true^roles=itil" id="assigned_to" table="sys_user" />

g_form.getControl can be used to check if this reference field in the UI macro is populated.


var isfilled = g_form.getControl("select_0IO:SYS_ID_OF_THE_MACRO_VARIABLE").length
if (isfilled === 0) {
return false;
} else {
return true;