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.

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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

19 REPLIES 19

We can do that as well. The only thing that needs to be kept in mind is coloring only those cells which are in start and end date.

We are unable to find a way to color it at that point.

that you can handle by comparing the start date in <j2:if> tag

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

With the below loop we are populating the value in the tabular form coming from the custom table. How we can compare within this loop and color the cells. Please help. I am unable to do so.

<j2:while test="$[gr.next()]">
<tr >
<td> $[gr.getDisplayValue('u_business_application') ]</td>
<td> $[gr.getDisplayValue('u_owner') ]</td>
<td id="demo1"> $[gr.getDisplayValue('u_start_date')]</td>
<td id="demo2"> $[gr.getDisplayValue('u_end_date')]</td>
<td> $[gr.getDisplayValue('u_refernce_id')]</td>
<td>$[gr.getDisplayValue('u_description')]</td>
<td id="xyz"></td>
<td id="abc"></td>
<td id="pqr"></td>
<td id="def"></td>
<td id="ghi"></td>
<td id="yes"></td>
<td id="app"></td>
<td id="page" ></td>
<td id="text1"></td>
<td id="text2"></td>
<td id="text3"></td>
<td id="text4"></td>

</j2:while>

Something like this

<j2:while test="$[gr.next()]">
<tr >
<td> $[gr.getDisplayValue('u_business_application') ]</td>
<td> $[gr.getDisplayValue('u_owner') ]</td>

<j2:if test="Compare here the value">
<td id="demo1" style="color:blue"> $[gr.getDisplayValue('u_start_date')]</td>

</j2:if>
<td id="demo2"> $[gr.getDisplayValue('u_end_date')]</td>
<td> $[gr.getDisplayValue('u_refernce_id')]</td>
<td>$[gr.getDisplayValue('u_description')]</td>
<td id="xyz"></td>
<td id="abc"></td>
<td id="pqr"></td>
<td id="def"></td>
<td id="ghi"></td>
<td id="yes"></td>
<td id="app"></td>
<td id="page" ></td>
<td id="text1"></td>
<td id="text2"></td>
<td id="text3"></td>
<td id="text4"></td>

</j2:while>

 

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

Thank you Ankur for the script but our requirement is to color the below cells (J,F,M,A,M,J,J,A,S,O,N,D) which are in blue but we can't use "<", ">" these symbols in <j2: if> tag.

Now for the second record, we have Start Date - 2021-04-23 and End Date - 2021-07-20. So we want A,M,J,J (April, May, June,July as in the start and end date) column in Blue for the second record (Second Row- HR-HR-General) rest should be in white

find_real_file.png