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

Hi,

value for that html hidden element would be blank initially.

It would be set using the client script section and then accessed in the processing script section

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,

 

this is the three scripts:

 

HTML:

________________________________

<tr>
<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_1" 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_1" value="" />
</td>
</tr>

...

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

________________________________

Client

________________________________

// imput users and planned hours
var us1 = gel('user_1').value;
var plH1 = gel('plHours_1').value;

alert('UI Page - cags_rp_user_multiple | Client Script | prjtsk : ' + prjtsk + ' ||| sd : ' + sd + ' ||| ed : ' + ed + ' ||| startdate : ' + startdate + ' ||| enddate : ' + enddate + ' ||| user_1 : ' + user_1 + ' ||| plHours_1 : ' + plHours_1);

// alert results for user_1 and plHours_1 : [object HTML]

________________________________

Processing script:

________________________________

gs.log('UI Page - cags_rp_user_multiple - Server ||| hid_prjtsk : ' + hid_prjtsk + ' ||| user 1 : ' + us1 + ' ||| plHours 1 : ' + plH1);

 

// results log for us1 and plH1 : any log is generated

________________________________

 

Can you tell me where is the error?

 

Thanks,

Alessio

Hi,

you need to set values to the hidden elements from client script and then that id value you can access

Client

________________________________

// imput users and planned hours
gel('user_1').value = 'User A' ;
gel('plHours_1').value = '5 Hours';

alert('UI Page - cags_rp_user_multiple | Client Script | prjtsk : ' + prjtsk + ' ||| sd : ' + sd + ' ||| ed : ' + ed + ' ||| startdate : ' + startdate + ' ||| enddate : ' + enddate + ' ||| user_1 : ' + user_1 + ' ||| plHours_1 : ' + plHours_1);

// alert results for user_1 and plHours_1 : [object HTML]

Processing script:

________________________________

gs.log('User is: ' + user_1);

gs.log('Hours is: ' + plHours_1);

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,

 

Sorry, it's not clear to me. I need the input from the page. For example, someone insert a user/planned hours in the pop up, then click ok. So i need to retrieve this information from the html to the processing script. Why did you set the values in the client?

 

Thanks,

Alessio

Hi,

Ok got it. Those values you will be setting in the UI page html section;

but to access the values from html section to processing script you will have to do something like this

create a hidden element

<input type="hidden" id="user_values" value="" />

in client script section; get all the text box values based on class

ensure all the input type as text has common class

<input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />

client script code to get all the text box values having common class

var arr = [];
var
inputs = $(".class1");
for(var i = 0; i < inputs.length; i++){
var value = $(inputs[i]).val();   
arr.push
(value.toString()); }
gel('user_values').value = arr.toString();

Now that you have set all the text box values as string in that hidden element access it in processing script

processing script:

gs.log('Text box values are : ' + user_values);

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