How can I access entered value on UI page to client or server side script?

Sagar24
Tera Contributor

I'm trying to open a UI page on clicking of a UI Button on the incident form and it has a input text field so that user can enter the bridge URL and I want to access it in the Server side script because I'm able to access it in client script of UI page as below. Also, is there any way we can send current object from UI action to UI page and access them in both client and processing script?

 

UI action:

find_real_file.png

 

UI Page:

find_real_file.png

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

you can pass sysId to UI page from UI action and then get it inside processing script

Remember you need to use g:ui_form to submit the UI page for the processing script to run

Sample below

UI Action:

dialog.setPreference('sysid', g_form.getUniqueValue());

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>
		<g:evaluate var="jvar_sysid"
					expression="RP.getWindowProperties().sysid"/> 

		<g:dialog_buttons_ok_cancel cancel="return onCancel();" ok="return onSubmit();"/>
		<input type="hidden" id="task_sys_id" name="task_sys_id" value="${jvar_sysid}"/>

	</g:ui_form>
</j:jelly>

Processing script:

var taskSysId = task_sys_id;

find_real_file.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Markus Kraus
Kilo Sage

In the processing script use:

this.bridge

Hi Markus,

Thanks for your response. We should be calling that in a function in processing script? Could you please provide the syntax?

I think you want to get the value of the input field right?

In the client script you have already figured that out i think. However i'd suggest you to use gel('bridge').value (that's more the "ServiceNow" way)

In the processing script you e.g. do:

var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('short_description', 'CONTAINS', this.bridge);
incidentGr.query();
while (incidenGr.next()) {
  gs.info('Incident contains bridge: ' + incidentGr.number);
}

// if you want to redirect the user after submit use:
// response.sendRedirect('/sp');

BTW, very important: You have to change to type of the submit button to 'submit', otherwise the processing script will never executed:

1.) Change type of the submit button

<button type="submit" label="Submit" class="btn btn-primary">Submit</button>

2.) Add an submit handler (change the g:ui_form on the top)

<g:ui_form onsubmit="return Func1();">

Only if you return true in Func1, it will then proceed to send the form (and as a result, call the processing script).

Thanks Markus, it really helped me a lot. Is there any way we can return the value of input field from UI page to UI action. Generally, I have a scenario where I was calling script include in ui action and passing current object as parameter. However, now i need to pass this entered value to script include as well along with current object. Are you aware of any scenarios?