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.

Passing variable from UI Page to UI Macro

Tommy Jensen
Giga Guru

I am having problems passing a varible from a UI Page to a UI Macro.

This is the UI Page

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<h1>Test</h1>
	<g:call function ="testMacro.xml" fieldName="xyz" />	
</j:jelly>

I want to pass the value "xyz" to the ui macro.

The ui macro looks like this ( I removed all unnecessary code)

<?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:function test="REQUIRED" />
	
    <div style="display:none">
        <g:evaluate object="true" >
			var token = gs.getSession().getSessionToken()?gs.getSession().session.getSessionToken():gs.getSessionToken();			
		</g:evaluate>
						
		<script>		
			var value = "${jvar_test}"
		</script>
    </div>

</j:jelly>

 

I want the variable "value" to contain "xyz" but I cannot get this to work. I have tried all kinds of kombinations using {} or [] prefixing with jelly. etc. But the variable value is empty.

 

1 ACCEPTED SOLUTION

Tommy Jensen
Giga Guru

I used Chuck's guidance here but it still did not work until I tried a differen variable name.

 

I changed fieldName to field_name and it worked.

 

So apparently variable names cannot contain uppper case letters. I must have overlooked that somewhere.

View solution in original post

3 REPLIES 3

Liyakhat
Mega Expert

Hello Jenson,

 

Please go through this site hope it will be helpful

https://dxsherpa.com/blogs/ui-macro-in-servicenow/

That link is no help. Actually it has less information than the official documentation and mention nothing about what I am asking about. 

Tommy Jensen
Giga Guru

I used Chuck's guidance here but it still did not work until I tried a differen variable name.

 

I changed fieldName to field_name and it worked.

 

So apparently variable names cannot contain uppper case letters. I must have overlooked that somewhere.