In a ui page , how can I access variables inside <g2:evaluate> in client script

Pragya8
Kilo Contributor

In a ui page , how can I access variables inside <g2:evaluate> in client script 

1 ACCEPTED SOLUTION

@Pragya 

you need to convert that to string

<g2:evaluate var="jvar_gr" object="true" jelly="true">

var sysparm_original = RP.getParameterValue('sysparm_original');
var sysparm_template_sysid = RP.getParameterValue('sysparm_template');

var arr = [];

var gr = new GlideRecord('sn_doc_html_template');
gr.addQuery("sys_id",sysparm_template_sysid);
gr.query();
if(gr.next())
{
gs.addInfoMessage(gr.name);

arr.push(gr.name.toString());
arr.push(gr.footnote.toString());

arr.push(gr.html_script_body.toString());
}
arr.toString();

</g2:evaluate>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

15 REPLIES 15

hi @Ankur Bawiskar , It is giving me this output "org.mozilla.javascript.NativeArray@114b585"

 

How can I access data of array, 

@Pragya 

you need to convert that to string

<g2:evaluate var="jvar_gr" object="true" jelly="true">

var sysparm_original = RP.getParameterValue('sysparm_original');
var sysparm_template_sysid = RP.getParameterValue('sysparm_template');

var arr = [];

var gr = new GlideRecord('sn_doc_html_template');
gr.addQuery("sys_id",sysparm_template_sysid);
gr.query();
if(gr.next())
{
gs.addInfoMessage(gr.name);

arr.push(gr.name.toString());
arr.push(gr.footnote.toString());

arr.push(gr.html_script_body.toString());
}
arr.toString();

</g2:evaluate>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Pragya 

Thanks for marking my response as helpful.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar  is there any other way to access variables in client script, 

As this is returing me a comma seperated string, but in my case name and html text can also have a comma, so it will be hard to segregate them.

Hi,

you can join the array with some other special characters to separate them out

arr.join('^');

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader