template in jelly tag.

priyanayak
Kilo Contributor

HI,

I wanted to know where the xml file defined in template attribute of jelly tag<g:insert>

example: <g:insert template="get_target_form_function.xml" />

In this get_target_form_function.xml this file must be defined to excess that in <g:insert>

2 REPLIES 2

Gurpreet07
Mega Sage

It should be a UI Macro. but it may be a OOTB UI Macro which may not be visible to us.


reedowens
Tera Contributor

Pryia,



The get_target_form_function.xml should be a ui_macro.   If it is not, then it's a ServiceNow ui_macro that is not visible to you and is only provided by ServiceNow on the platform from one of the developers of that specific application.



If you are doing this your self and can't seem to get the UI Macro to load, then it's a caching issue with the macro.   To solve use https://yourinstancename.service-now.com/cache.do to clear the cache and try again.



There are several different ways to include/call/etc a UI Macro from another macro.   Here is an except from the WIKI:



6 <g:insert> Versus <g:inline> Versus <g:call>

The <g:insert> tag inserts a Jelly file into your Jelly in a new context. This means you cannot access the variables previously established in your Jelly. The <g:inline> tag inserts a Jelly file into your Jelly in the same context. This means that the inserted Jelly can access the variables you previously established and it can change the values of those variables.



<g:insert template="get_target_form_function.xml" />



<g:inline template="element_default.xml" />


6.1 <g:call>

For better encapsulation, the <g:call> tag may be used. Your function will only have access to the values passed to it. The Jelly context will look the same after a call as before the call. This means you cannot set a global variable here and read it later. This also means you can't mistakenly set a global variable called "jvar_temp" and overwrite a variable that somebody else was relying on.


Passing values, if needed, is done explicitly by including the name of the parameter on the <g:call> line followed by the equal sign followed by the value in quotes:



   <g:call function="collapsing_image.xml" id="${jvar_section_id}" image="$[jvar_cimg]"       first_section_id="${jvar_first_section_id}" image_alt="${jvar_cimg_alt}"/>


If values are passed, and you want to have defaults or required parameters, your Jelly referenced in the function must then include a line to declare whether the parameters are required or have a default value:



   <g:function id="REQUIRED" image="REQUIRED" image_prefix="" image_alt="REQUIRED"/>


The example above indicates that 3 of the parameter are required and one parameter is option with a blank default value. Note that if you are not passing values or if you do want to have default or required values, you do not need to include the <g:function> line at all. In general, however, you will want to include a <g:function> line.


The value can then be referenced in your template by prepending the "jvar_" prefix to the parameter's name:



   <img id="img.${jvar_id}" src="images/${jvar_image}" alt="${jvar_image_alt}"       onclick="toggleSectionDisplay('${jvar_id}', '${jvar_image_prefix}','${jvar_first_section_id}');"/>


For <g:call>, parameters may also be pass implicitly as a list of named variables in an "arguments" parameter:



   <g:call function="item_link_default.xml" arguments="sysparm_view,ref_parent,jvar_target_text"/>


As an alternative to passing variables into the function via separate tag arguments, it is possible to pass a list of variables in a single 'arguments' argument. All variables identified by name (comma separated) in the argument parameter are re-introduced within the function under the exact same name (e.g. inside the function template, we'd have variables sysparm_view, ref_parent, and jvar_target_text available to us).


The function template may return a value to the calling template using the return= attribute. Within the function the jvar_answer variable sets the return value.



   <g:call function="item_body_cell_calc_style.xml" arguments="jvar_type" return="jvar_style"/>