How to get current form values in UI macro jelly script

madhuabbaraju
Kilo Contributor

Hi All,

I have created a formatter and UI macro. And formatter is added to incident form. Now i want to display current incident fields to the formatter.

Created UI macro with below script but it is not showing any values. Please help me.

 

<?xml version = "1.0" encoding = "utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate object="true" var="jvar_gr">
var sys_id = current.getValue('sys_id');
var gr = new GlideRecord("incident");
gr.addQuery('sys_id', sys_id);
gr.query();
gr;
</g:evaluate>
<j:if test="${jvar_gr.next()}">
<j:set var="jvar_phase2" value= "${gr.number} "/>
<j:set var="jvar_phase2" value= "${gr.priority} "/>
<j:set var="jvar_phase2" value= "${gr.impact} "/>
<j:set var="jvar_phase2" value= "${gr.state} "/>
</j:if>

 </j:jelly>

 

TIA

Madhuri

5 REPLIES 5

Omkar Mone
Mega Sage

Hi 

PFB the link :-

https://community.servicenow.com/community?id=community_question&sys_id=f1cb03e1db9cdbc01dcaf3231f96...

 

Hope this helps you.

 

Mark Correct if it helps.

Warm Regards,

Omkar Mone

find_real_file.png

www.dxsherpa.com

Hi Omkar,

 

Thanks for the reply. But i have to use multiple <g2 evaluates for each variable ?? Can't be possible to display all fields in single g2 tag?

 

felladin
Tera Guru

Hello,

I believe you should use g_form.getUniqueValue() instead of current.getValue().
If the UI Macro runs on the client.

With regards
Anton

andrew_venables
ServiceNow Employee
ServiceNow Employee

When using a UI macro on the form via a formatter you only have access to current in phase2 of the jelly script.

Meaning, this doesn't work:

 

${current.getValue('number')}

but this does:

$[current.getValue('number')]

 

So for your script i think you can simplify it to something like this (which will display number, priority, impact and state on the form):

<?xml version = "1.0" encoding = "utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

Number: $[current.getValue('number')]<br/>
Priority: $[current.getValue('priority')]<br/>
Impact: $[current.getValue('impact')]<br/>
State: $[current.getValue('state')]<br/>

</j:jelly>