Pass form value from UI Action to HTML in UI Page

Chenab Khanna
Tera Expert

Hi

I have a requirement to hide few choice values of a field based on HR Service when the button is clicked.

When a user clicks "Rescind" button in Lifecycle event case, a dialog window appears and user is asked to submit Rescind reason. 

My requirement is, based on the HR Service of the LE Case, i need to display certain choice values.

Backend code -

A UI Page is called in the UI Action which is displaying the choice values - 

UI Action - 

ChenabKhanna_0-1665589846290.png

 

UI Page - 

HTML - 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form id="LE rescind dialog">
<style type="text/css">
#le_rescind_dialog_footer input {
width: 100%;
}

.required-marker {
content: "*";
}
</style>
<script>
$j(document).ready(function() {
$j("#le_rescind_comment").focus();
});
alert("hello "+RP.getWindowProperties().get('sysparm_v1'));
</script>
<g:evaluate var="jvar_sysparm_v1" expression="RP.getWindowProperties().get('sysparm_v1')" />
<g:evaluate object='true' jelly='true'> var isRequired = 'true'; </g:evaluate>
<g:evaluate var="jvar_gr" object='true' jelly='true'> var reasons = JSON.parse(new
sn_hr_le.LifeCycleEventsClientCallableUtil().getRescindReasonsUIAction("${jvar_sysparm_v1}")); </g:evaluate>

 

The lines highlighted in red is how i am trying to pass HR Service as an argument to the script include but it is returning null.

Can anyone help me with correct syntax or any other way to pass a form value from UI Action to HTML in UI Page?

 

 

5 REPLIES 5

Ahmed Drar
Tera Guru
Tera Guru

Hi Chenab,

 

I think you should use RP.getParameterValue("sysparm_v1") to capture HR Service .

 

Have a look at this post

https://www.servicenow.com/community/developer-forum/how-can-i-pass-arguments-from-ui-action-to-ui-p...

 

Community Alums
Not applicable

you should use this

<g:evaluate>

      var sysIDCase = RP.getParameterValue("sysparm_case_sysId");

     var hr= RP.getParameterValue("sysparm_v1");

      gs.log("sysIDCase  = " + sysIDCase  + " / " + " hr = " + hr);

</g:evaluate>

WellingtonF
Tera Contributor
You can use the example that ZAK gave and call this variable whenever you need.

 

 

<g:evaluate>

      var sysIDCase = RP.getParameterValue("sysparm_case_sysId");
     var hr = RP.getParameterValue("sysparm_v1");   

</g:evaluate>

<div> 
<p>ID: ${sysIDCase}</p>
<p>HR: ${hr}</p>
</div>

 

 

-O-
Kilo Patron
Kilo Patron

Parameters can be just accessed by name.

 

E.g. one could write

<script>
	alert("sysparm_v1: $[ sysparm_v1 ]");
</script>

and when the said UI Page is invoked, one will get a prompt with the value of parameter sysparm_v1.

 

Note that I'm using $[ ] and not ${ }.

${ } is phase 1 expression, $[ ] is phase 2 expression.

 

(Jelly is evaluated in two phase - the 1st one is supposed to build the cached part of pages/macros, while the 2nd one the not-cached, dynamic part. So one would write stuff that does not change from one invocation to the next invocation for phase 1 and the stuff that changes from one invocation to the next for phase 2.)

 

The same variable can be accessed in evaluate Jelly nodes also by name:

<g2:evaluate jelly="true">
	gs.info('sysparm_v1: ' + jelly.sysparm_v1);
</g2:evaluate>

 

Note again that I am using g2: namespace vs. g: namespace - same cached vs. dynamic part of a UI Page/UI Macro story.

Also note that I am indicating to the evaluator that I want to have access to Jelly variables (attribute jelly="true") and note that the parameter (sysparm_v1) is a property of the "global" jelly object.

 

A clarification: writing

alert("hello "+RP.getWindowProperties().get('sysparm_v1'));

would entirely be evaluated on client side, where there is no RP object and thus the entire script is invalid.

If one wants to evaluate something server side in a UI Page or UI Macro, that something has to be inside an evaluate node (<g:evaluate/> or <g2:evaluate/>) or inside Jelly expressions: ${ } or $[ ].