How do I get an HTML variable into a client script on a UI Page?

ServiceNowSteve
Giga Guru

Hello All,

I hope this one is simple but I really can't figure it out. I have a UI page with the line

<g:evaluate var="sysparm_number" expression="RP.getWindowProperties().sysparm_number" />

inside of the HTML code. This passes the 'number' field of my form to the HTML and it works great.

My next challenge is passing that same number to the Client Script section in the UI page, how would I go about referencing that sysparm_number variable or is there another way to reference it more directly in the client script?

1 ACCEPTED SOLUTION

Hi,

Something like this

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>
		
		<g:evaluate var="sysparm_number" expression="RP.getWindowProperties().sysparm_number" />
		
		<input type="hidden" id="sysparm_number" name="sysparm_number" value="${sysparm_number}"/>
	
		<table border="0" width="100%">
			
			<tr>
				<td>
					<g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/>
				</td>
			</tr>
		</table>
	</g:ui_form>
	
</j:jelly>

Client Script:

function onCancel() {
	GlideDialogWindow.get().destroy();
	return false;
}

function onSubmit() {
	return true;
}

Processing Script:

updateRecord();
function updateRecord() {
    var app = new GlideRecord("tableName");
    if(app.get('number', sysparm_number)){
        app.field1 = 'Your Value';
        app.update();
    }
    var urlOnStack = gs.getUrlOnStack();
    response.sendRedirect(urlOnStack);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do you wish to send it via some trigger function?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes, what I want to do is have it go back to the originating record and add a note for the user. I tried doing this directly from my UI action but it had problems with rendering the UI page and updating the form at the same time so I am going to essentially have the UI Page do the update after it renders.

Hi,

you can store the value being passed in hidden html element

Then access the hidden html element value in the processing script, update the record

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Do you have an example or can you point me to some documentation that does this for reference?