How to pass ui_reference varible from HTML to Processing Script in UI Page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 09:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 10:12 AM
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
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:42 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 03:49 AM
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
