Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

way to pass variables from client script to HTML in UI page ? Thanks in advance!

Sunidhi Srivast
Kilo Contributor

Hi,

Can anyone tell me the way to pass variables from client script to HTML in UI page ? 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi,

you will have to set the value of some html tag using dom

Something like this

<div class="col-md-5 text-right" style="padding-left:3px">
<g:form_label for="service_select">
${gs.getMessage("How many request you want to clone ")}
</g:form_label>
</div>

<p id="my_id" style="display:none"></p>
<div class="col-md-5 text-left" style="padding-left:3px" >
<select id="times" name="times">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

I am fetching "times " in client script as below: 

$j("#times").on("change", function(e) {
var testt = $j("#times").val();
alert(testt);

document.getElementById('my_id').innerHTML = testt;

document.getElementById('my_id').style.display = '';
});

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Ankur Bawiskar
Tera Patron

@Sunidhi Srivastava 

Please explain any script which you have started and where are you stuck

Regards
Ankur

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

This is the HTML part: 

<div class="col-md-5 text-right" style="padding-left:3px">
<g:form_label for="service_select">
${gs.getMessage("How many request you want to clone ")}
</g:form_label>
</div>
<div class="col-md-5 text-left" style="padding-left:3px" >
<select id="times" name="times">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

I am fetching "times " in client script as below: 

$j("#times").on("change", function(e) {
var testt = $j("#times").val();
alert(testt);
});

Now I again want this value 'testt' to be used in HTML for further functioning. How can I do so?

Hi,

you will have to set the value of some html tag using dom

Something like this

<div class="col-md-5 text-right" style="padding-left:3px">
<g:form_label for="service_select">
${gs.getMessage("How many request you want to clone ")}
</g:form_label>
</div>

<p id="my_id" style="display:none"></p>
<div class="col-md-5 text-left" style="padding-left:3px" >
<select id="times" name="times">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

I am fetching "times " in client script as below: 

$j("#times").on("change", function(e) {
var testt = $j("#times").val();
alert(testt);

document.getElementById('my_id').innerHTML = testt;

document.getElementById('my_id').style.display = '';
});

Regards
Ankur

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

Hi,

Please help me with this

<div class="col-md-5 text-right" style="padding-left:3px">
<g:form_label for="service_select">
${gs.getMessage("How many request you want to clone ")}
</g:form_label>
</div>
<div class="col-md-5 text-left" style="padding-left:3px" >
<select id="times" name="times">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

</div>

I am getting input from above code: say the input number is = n;

now I want to run the following HTML code for n times; how can I do that?

<g:evaluate var="jvar_transfer_methods" jelly="true" object="true">

var sysId = RP.getParameterValue('sysparm_sys_id');
var tableName = RP.getParameterValue('sysparm_table_name');


var transferMethods = hr_TransferCase.getTransferMethods(tableName, sysId);
var oneTransferMethod = transferMethods.length == 1;
transferMethods;
</g:evaluate>