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.

Use html variables in client and processing script of ui page

Rj27
Mega Guru

I have defined two variables in my html code as below :

<g:evaluate var="jvar_number" expression="RP.getWindowProperties().get('sysparm_number')" />
<g:evaluate var="jvar_createdBy" expression="RP.getWindowProperties().get('sysparm_createdBy')" />


<p>${jvar_number}</p>
 <p>${jvar_createdBy}</p

Getting these values displayed as expected on ui page.

I am trying to access this on my client script using alert.
I am trying this in my client script..
   

var nm = gel('jvar_number').value;
	alert(nm);

But this alert is not coming..Is this because id needs to be passed ?
Also, can i access this in processing script also becasue i need to append these parameters in my redirection url.

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello,

I think yes you need to use document.getElementById('your ID').value;

please add this piece of code in your UI page HTML part

<input type="hidden" value=${jvar_number}/ id="value1">

Also add this in client script to access the value

alert(document.getElementById('value1').value);

Please try this and if it works please mark my answer correct

View solution in original post

7 REPLIES 7

Mohith Devatte
Tera Sage
Tera Sage

Hello,

I think yes you need to use document.getElementById('your ID').value;

please add this piece of code in your UI page HTML part

<input type="hidden" value=${jvar_number}/ id="value1">

Also add this in client script to access the value

alert(document.getElementById('value1').value);

Please try this and if it works please mark my answer correct

This helped. Thanks !

Hi Mohith,
how can i access this in my processing script ?
I have to create a url where these parameters will append.
and this url will be redirected, so i need these values in processing script as well i guess.

referring this solution but it's not working in my case..
https://community.servicenow.com/community?id=community_question&sys_id=9d9fe5b5dba6dcd4d5c4d9d9689619c2

Hello,

Please try the below method

UI page process scripts

If your UI page contains a form (uses the <g:form> tag), you can submit the form and have the process script run.

Make sure your HTML code is enclosed between <g:ui_form> your HTML code </g:ui_form>

The processing script can naturally access fields on the form. For example, if your form contained the application_sys_id field:
<g:ui_form><p>Click OK to run the processing script.</p> <g:dialog_buttons_ok_cancel ok = "return true"/> <input type = "hidden" name = "application_sys_id" value = "499836460a0a0b1700003e7ad950b5da"/> </g:ui_form>
You can access the field using application_sys_id:
var application = new GlideRecord('hr_application');
 application.get(application_sys_id);
 application.status = "Rejected";
 application.update();
 var urlOnStack = GlideSession.get().getStack().bottom();
 response.sendRedirect(urlOnStack);

Please mark it helpful if it helped you