Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to pass ui_reference varible from HTML to Processing Script in UI Page?

alebuc
Tera Expert

Hi,

 

I have programmatically create 10 reference fields in my ui page. Following https://community.servicenow.com/community?id=community_question&sys_id=afb88761db5cdbc01dcaf3231f96....

HERE IS THE CODE:

<j2:set var="jvar_serialnumbers" value="1" />
<j2:while test="$[jvar_serialnumbers != 10]">
<table>
<tr class="item" id="user_$[jvar_serialnumbers]">
<td >
<label>User</label>
<g:ui_reference name="QUERY:group.active=true^group.u_tipologia_struttura=1^group.u_imported_from=100^user.active=true^user.roles=pps_resource" id="user_$[jvar_serialnumbers]" table="sys_user_grmember"/>
</td>
<td> <marquee behavior="scroll" direction="left"><div style="font-weight:bold;margin-right:10px"> </div></marquee> </td>
<td>
<label>Planned Hours</label>
<input type="text" id="plHours_$[jvar_serialnumbers]" value="" />
</td>
</tr>
</table>
<g2:evaluate jelly="true" var="jvar_serialnumbers" expression="jelly.jvar_serialnumbers = parseInt(jelly.jvar_serialnumbers) +1; " />

</j2:while>

Now I need to used the content of this variables in the processing script. In particular, if are used 5 of the variables in the UI Page, is there a way to pass to the processing script all the 5 valorized variables and not just the last one?

The variables, of the above script in which I'm interested in, are:  id="user_$[jvar_serialnumbers]" and id="plHours_$[jvar_serialnumbers]", both depends on the variable jvar_serialnumbers.

 

Thanks,

Alessio

9 REPLIES 9

vkachineni
Kilo Sage

Try with one html control first

Add a name to this input. Same as id.

<input type="text" name="plHours_$[jvar_serialnumbers]" id="plHours_$[jvar_serialnumbers]" value="" />

in the processing script can you log

gs.log("plHours_1 = " + plHours_1);

gs.log("plHours_2 = " + plHours_2);

 

Lets see if the planned hours are available in the variables in the processing script

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Hi,

 

if I try to add the input line in HTML and log gs.log("plHours_1 = " + plHours_1); as you suggest, the processing script does not even start since the variable plHours_1 is not defined.

 

But I am able to retrive from the HTML the value of "jvar_serialnumbers", since jvar_serialnumbers is set in HTML as variable.

 

Any idea?

 

Thanks,

Alessio

Hi,

you need to define html input type as hidden set the value and then set that in client script in some variable and use that in processing script

<input type="hidden" name="plHours_serialNumber1" id="plHours_serialNumber1" value="" />

client script

var serialNumber1 = gel(gel('plHours_serialNumber1').value);

processing script directly access serialNumber1 variable

var serialNum1 = serialNumber1;

I believe you need those many html input hidden elements

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi,

 

which is the value that I should set for the variable with id=user_1 and id=plHours1?

 

if I put the input like:

<input type="hidden" name="plHours_1" id="plHours_1" value="" />

 

and strore the variable in the client in an other variable it returns an html object not the value insert in the field.

 

Thanks,

Alessio