Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

UI Macro and UI Page prefilling data

0890KM
Tera Contributor

Hey All,

 

I want my UI Macro to pass data inputs from the RITM variables into the UI page input fields.  What am I doing wrong?

 

Here's my UI Macro 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">

    <button type="button" onclick="getAddress()">Open Verification Address</button>
    <script>
        function getAddress() {
            var inputs = {};

            inputs['address'] = g_form.getValue("usps_street_address");
            inputs['city'] = g_form.getValue("uspsCity");
            inputs['state'] = g_form.getValue("uspsState");
            inputs['zipcode'] = g_form.getValue("uspsZipcode");

            // Create GlideDialogWindow
            var gdw = new GlideDialogWindow('name_of_ui_page'); 
            gdw.setTitle("Verify Address Info");


            // Pass the inputs as data
            gdw.setPreference('address', inputs['address']);
            gdw.setPreference('city', inputs['city']);
            gdw.setPreference('state', inputs['state']);
            gdw.setPreference('zipcode', inputs['zipcode']);
            gdw.setSize(800, 600);
            gdw.render();
    }
    </script>
</j:jelly>

 

This is the UI Page code: 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">

<html>

<head>
    <style>
        input[type="text"] {
            width: 250px;
            padding: 6px;
            box-sizing: border-box;
        }

        .form-field {
            margin-bottom: 12px;
        }

        label {
            display: block;
            margin-bottom: 4px;
            font-weight: bold;
        }
    </style>
</head>

<j:set var="address" value="${preferences.address}" />
<j:set var="city" value="${preferences.city}" />
<j:set var="state" value="${preferences.state}" />
<j:set var="zipcode" value="${preferences.zipcode}" />

<g:ui_macro name="name_of macro">
    <g:param name="address" value="${address}" />
    <g:param name="city" value="${city}" />
    <g:param name="state" value="${state}" />
    <g:param name="zipcode" value="${zipcode}" />
</g:ui_macro>

<div>
    <div>
        <h3><strong>Please verify the address</strong></h3>
        <p>To ensure we have the correct information on file, enter your full address below. This helps us confirm your location and provide accurate service.</p>
    </div>
    <h3>Mailing Address</h3>
    <div class="form-field">
        <label for="addrStreet">Street Address</label>
        <input type="text" id="addrStreet" value="${address}" />
    </div>
    <div class="form-field">
        <label for="addrCity">City</label>
        <input type="text" id="addrCity" value="${city}" />
    </div>
    <div class="form-field">
        <label for="addrState">State</label>
        <input type="text" id="addrState" value="${state}" />
    </div>
    <div class="form-field">
        <label for="addrZip">ZIP Code</label>
        <input type="text" id="addrZip" value="${zipcode}" />
    </div>
</div>

<div>
    <button id="verifyBtn" class="btn btn-primary">Verify Address</button>
</div>

</html>
</j:jelly>

 

 

1 ACCEPTED SOLUTION

lauri457
Tera Sage

GlideDialogWindow is deprecated use GlideModal instead: GlideDialogWindow (deprecated) | ServiceNow Developers

 

To fix the issues:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
        <!--  the props can be accessed with RP -->
	<j:set var="jvar_address" value="${RP.getWindowProperties().get('address')}" />
	<j:set var="jvar_city" value="${RP.getWindowProperties().get('city')}" />
	<j:set var="jvar_state" value="${RP.getWindowProperties().get('state')}" />
	<j:set var="jvar_zipcode" value="${RP.getWindowProperties().get('zipcode')}" />
	<html>

	<head>
		<style>
			input[type="text"] {
				width: 250px;
				padding: 6px;
				box-sizing: border-box;
			}

			.form-field {
				margin-bottom: 12px;
			}

			label {
				display: block;
				margin-bottom: 4px;
				font-weight: bold;
			}
		</style>
	</head>


	<div>
		<div>
			<h3><strong>Please verify the address</strong></h3>
			<p>To ensure we have the correct information on file, enter your full address below. This helps us
				confirm your location and provide accurate service.</p>
		</div>
		<h3>Mailing Address</h3>
		<div class="form-field">
			<label for="addrStreet">Street Address</label>
			<input type="text" id="addrStreet" value="${jvar_address}" />
		</div>
		<div class="form-field">
			<label for="addrCity">City</label>
			<input type="text" id="addrCity" value="${jvar_city}" />
		</div>
		<div class="form-field">
			<label for="addrState">State</label>
			<input type="text" id="addrState" value="${jvar_state}" />
		</div>
		<div class="form-field">
			<label for="addrZip">ZIP Code</label>
			<input type="text" id="addrZip" value="${jvar_zipcode}" />
		</div>
	</div>

	<div>
		<button id="verifyBtn" class="btn btn-primary">Verify Address</button>
	</div>

	</html>
</j:jelly>

 

Or this works too

<g:evaluate>
	var inputs = {};
	inputs["address"] = RP.getWindowProperties().get('address');
</g:evaluate>
.....
<div class="form-field">
	<label for="addrStreet">Street Address</label>
	<input type="text" id="addrStreet" value="${inputs.address}" />
</div>

 

View solution in original post

2 REPLIES 2

lauri457
Tera Sage

GlideDialogWindow is deprecated use GlideModal instead: GlideDialogWindow (deprecated) | ServiceNow Developers

 

To fix the issues:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
        <!--  the props can be accessed with RP -->
	<j:set var="jvar_address" value="${RP.getWindowProperties().get('address')}" />
	<j:set var="jvar_city" value="${RP.getWindowProperties().get('city')}" />
	<j:set var="jvar_state" value="${RP.getWindowProperties().get('state')}" />
	<j:set var="jvar_zipcode" value="${RP.getWindowProperties().get('zipcode')}" />
	<html>

	<head>
		<style>
			input[type="text"] {
				width: 250px;
				padding: 6px;
				box-sizing: border-box;
			}

			.form-field {
				margin-bottom: 12px;
			}

			label {
				display: block;
				margin-bottom: 4px;
				font-weight: bold;
			}
		</style>
	</head>


	<div>
		<div>
			<h3><strong>Please verify the address</strong></h3>
			<p>To ensure we have the correct information on file, enter your full address below. This helps us
				confirm your location and provide accurate service.</p>
		</div>
		<h3>Mailing Address</h3>
		<div class="form-field">
			<label for="addrStreet">Street Address</label>
			<input type="text" id="addrStreet" value="${jvar_address}" />
		</div>
		<div class="form-field">
			<label for="addrCity">City</label>
			<input type="text" id="addrCity" value="${jvar_city}" />
		</div>
		<div class="form-field">
			<label for="addrState">State</label>
			<input type="text" id="addrState" value="${jvar_state}" />
		</div>
		<div class="form-field">
			<label for="addrZip">ZIP Code</label>
			<input type="text" id="addrZip" value="${jvar_zipcode}" />
		</div>
	</div>

	<div>
		<button id="verifyBtn" class="btn btn-primary">Verify Address</button>
	</div>

	</html>
</j:jelly>

 

Or this works too

<g:evaluate>
	var inputs = {};
	inputs["address"] = RP.getWindowProperties().get('address');
</g:evaluate>
.....
<div class="form-field">
	<label for="addrStreet">Street Address</label>
	<input type="text" id="addrStreet" value="${inputs.address}" />
</div>

 

0890KM
Tera Contributor

Thank you!