Refresh ui page without reloading it.

Nikita9
Mega Expert

Hi All,

 

I have a requirement where i need to give specified time to user to review the form. when user clicks on alert button then my ui page should refresh. So that i can get all default values that was there on that ui page and my timer can restart .

I am not getting any code to refresh ui page so that my ui page timer restarts with default values. 

find_real_file.png

Pls help.

 

Regards,

Nikita

1 ACCEPTED SOLUTION

rahulpandey
Kilo Sage

Hi Nikita,

I have created a similar case and I could achieve it. Here is what I have done.

UI action

function openPage(){
		var dialog = new GlideDialogWindow('Test UI');

	dialog.setTitle(getMessage('Testing 123'));
	dialog.setPreference('label', 'Can you please choose an option?'); // This is the input for UI page, which would be default

	dialog.render();
}

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>
	<!-- Get values from dialog preferences passed in -->
	<g2:evaluate var="jvar_label" expression="RP.getWindowProperties().get('label')" />
	<g2:evaluate var="jvar_optionName"  jelly="true" object="true" >

		var options =RP.getWindowProperties().get('optionName');
		options = options.split(",");
		var choiceArray = [];
			//<![CDATA[
		for(var i = 0; i<options.length; i++){
			choiceArray.push(options[i]);							 
		}
//]]>
	choiceArray;


	</g2:evaluate>
	<input id="label_id" type="HIDDEN" value="$[jvar_label]"/>
	<!-- Set up form fields and labels -->
	<table width="100%">
		<tr>
			<td>
				<g:ui_choice_input_field name="TestChoice" id="chooseOption" label="$[jvar_label]" mandatory="true">
					<option value="">${gs.getMessage('-- None --')}</option> 
					<option value="other">Other</option>
				</g:ui_choice_input_field>
			</td>
		</tr>
		<tr>
			<td colspan="2">
			</td>
		</tr>
		<tr id="dialog_buttons">
			<td colspan="2" align="right">
				<g:dialog_button_ok ok="return getChoices()" ok_type="button" />
			</td>
		</tr>
	</table>
</g:ui_form>
	<button onclick="reincarnate()">Cancel</button>
</j:jelly>

Client Script

function reincarnate(){
	var labelValue = document.getElementById("label_id").value;
	GlideDialogWindow.get().destroy();
	setTimeout(function(){ openPage(labelValue);}, 1000);
	
}
function openPage(value){
		var dialog = new GlideDialogWindow('Test UI');

	dialog.setTitle(getMessage('Testing 123'));
	dialog.setPreference('label', value);
	dialog.render();
}

In above example, I could destroy the GlideModal and recreate it.

In your case, You could create hidden input fields and store the values of parameters inside those hidden inputs.

Below are the inputs I see you are receiving in UI page

<j:set var="jvar_email" value="${JS:RP.getWindowProperties().get('email_ids')}" />
<j:set var="jvar_ccemail" value="${JS:RP.getWindowProperties().get('ccemail_ids')}" />
<j:set var="jvar_bccemail" value="${JS:RP.getWindowProperties().get('bccemail_ids')}" />
<j:set var="jvar_blacklist" value="${JS:RP.getWindowProperties().get('bclist_ids')}" />
<j:set var="jvar_sys_id" value="${JS:RP.getWindowProperties().get('sys_id')}" />
<j:set var="jvar_subject" value="${JS:RP.getWindowProperties().get('subject')}" />

Further on cancel, you can reopen the UI page by passing setpreferences from hidden fields.

Note : You need to use setTimeout and get value of hidden fields into variable before detroying the GlideModal.

 

 

View solution in original post

19 REPLIES 19

Hi,

Do you want to reload the form?

you cannot refresh the UI page without reloading it

If user clicks Cancel the UI page will be destroyed.

They will have to again click on that UI action to invoke the UI page

Regards
Ankur

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

ok. Can you pls tell me what code to write to reload the form.

Hi,

so you want to reload the form when they click cancel

update as below

if (diff < calctym) {

var c = confirm('The standard time for this page is '+calctym + 'seconds & only '+tymlimit+'seconds is elapsed now. Please Click Cancel to review this page else click OK.');
if (c) {

location.reload();

} else {

// alert('You clicked Cancel button')
return false;

}
}

Regards
Ankur

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

hi Ankur,

Reloading/Refreshing of UI page isn't possible? I want to see the default ui page when user clicks on Cancel button.

 

location.reload(); is reloading RITM form and removing ui page too.

 

Regards,

Nikita 

 

Hi Nikita,

Then in that case as I mentioned earlier you need to call the UI page again

But this is not tested

// your new Code to GlideDialogWindow

var dialog = new GlideDialogWindow("ui page name"); //name of UI page here
dialog.setTitle("Show value"); //Set the dialog title
dialog.setPreference("sysparm_sysID", ''); //Pass your parameter gere
dialog.render(); //Open the dialog
//GlideDialogWindow.get().destroy();

Regards
Ankur

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