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 access jvar in UI page client script

purbali1
Giga Expert

Hi,

I have one value set on jvar on UI Page HTMl and I want to show one alert message depending on the value set on submit of the UI page.

For that reason I want to check jvar value on onSubmit function of the UI page client script. I am not aware of the syntax on how to do that

HTML-

<g:evaluate expression="RP.getParameterValue('sysparm_flag')" var="jvar_flag"/>

Client Script-

function onSubmit() {

if (jvar_flag===<something>)       // not sure of the syntax

{

alert("something");

return false;

}

}

5 REPLIES 5

Chuck Tomasi
Tera Patron

jvar_ is a server side construct. You would have to set a hidden field with that value for the client script to get access. The client script/browser only knows HTML, CSS, and JavaScript.



Something like this could help.



<input type="text" name='flag' value="${jvar_flag}" />



Then your client script can get it with the traditional means of accessing input field values.


Hi Chuck,



I might sound silly but how do I access input field values in the client script.



Should I use g_form.setValue.


I order to access the variable. Provide an id to the tag.


Use gel("idNAME").value to access the value of the tag.




Let me know if this was helpful/correct.


find_real_file.png



Please let me where exactly I am doing mistake, as both fields(reason and sys_id) are returning null.