How to stop UI Page Redirection after Clicking 'OK'

Mrman
Tera Guru

Hi All,

I have a UI page for transferring a HRCase to IT Group and once I select the Assignment group and Click OK .

The issue I have is after clicking on OK , the page is getting redirected and not staying on the same form . Please let me know what changes need to be done for achieving this . Below is the UI Page Client Script part .

find_real_file.png

function yesnoCheck(val)
{
	try
	{
		gel('selected_decision').value = val;
		if(val == '1')
		{
			gel('worknotesection').style.display = 'block';
			gel('commentssection').style.display = 'block';
			
		}
		else
		{
			gel('worknotesection').style.display = 'none';
			gel('commentssection').style.display = 'none';
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function valdiateGrpValue()
{
	var finalresult;
	var groupErrorBlock = $j('#groupError');
	var groupValue = gel("assignment_group").value;
	
	if(groupValue == '')
	{
		groupErrorBlock.html(getMessage('Please select a group'));
		finalresult = false;
	}
	else
	{
		groupErrorBlock.html('');
		finalresult = true;
	}
	
	return finalresult;
}

function valdiateDecisionValue()
{
	try
	{
		var finalresult = false;
		var decErrorBlock = $j('#decError');
		var decisions = document.getElementsByName("decision");
		var tlscore = '';
		for (var i = 0, len=decisions.length; i< len; i++)
		{
			if (decisions[i].checked )
			{
				tlscore = decisions[i].value; // if so, hold its value in tlscore
				finalresult = true;
				break; // and break out of for loop
			}
		}
		
		if(finalresult)
		{
			decErrorBlock.html('');
			if(tlscore == '1')
			{
				var notesErrorBlock = $j('#noteError');
				if(gel('worknotes').value == '' || gel('worknotes').value == ' ' || gel('worknotes').value == 'undefined')
				{
					notesErrorBlock.html(getMessage('Please fill Work Notes'));
					finalresult=false;
				}
				else
				{
					notesErrorBlock.html('');
				}
			}
		}
		else
		{
			decErrorBlock.html(getMessage('Please select decision'));
		}
		
		return finalresult;
	}
	catch(e)
	{
		jslog(e);
	}
}

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

function submitOk() {
	var result = $("assignment_group").value != undefined;
	
	if(!valdiateGrpValue())
		{
		result=false;
	}
	
	if(!valdiateDecisionValue())
		{
		result=false;
	}
	
	if (result)
		{
		$('cancel_button').addClassName('disabled');
		$('ok_button').addClassName('disabled');
	}
	
	return result;
}
15 REPLIES 15

Brad Bowman
Kilo Patron
Kilo Patron

Have you tried a line like this?

action.setRedirectURL(current);

Hi @Brad Bowman ,

I have tried this and it is not working in the UI page .

I have another query , could you please let me know how to hide the highlighted on UI page . I am pasting the HTML of the UI page .

I have already commented a line , bit it is not working

find_real_file.png

<?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 id="transfer_to_it">
		<script src="scripts/heisenberg/heisenberg_all.js" />
		<g:requires name="styles/heisenberg/heisenberg_all.css" includes="true" />
		<j:set var="jvar_sys_id" value="${sysparm_sys_id}" />
		<j:set var="jvar_table_name" value="${sysparm_table_name}" />
		

			<div class="row" style="margin-bottom:10px">
				<div class="col-md-12">
					<p style="font-size: 15px">${gs.getMessage("Select the 'Assignment Group' to transfer this case.")}</p>
				</div>
			</div>
		
		<div class="form-group is-required row">
			
					<label for="assignment_group" class="col-sm-3 text-right" style="padding-left:1px">
						<span class="required-marker"></span>${gs.getMessage('Assignment Group')}
					</label>
					<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
						<g:ui_reference name="assignment_group" value="${jvar_assignment_group}" query="sys_idIN$[gs.getProperty('sn_hr_core.INF_Anx_IT_Groups')]" table="sys_user_group" required="required" />
						<p class="help-block" id="groupError" role="alert"></p>
					</div>
			<label for="decision" class="col-sm-3 text-right" style="padding-left:1px">
				<span class="required-marker"></span>${gs.getMessage('Decision')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<label class="radio-inline" style='color:#303a46;'>
			<input type="radio" id="decision1" name="decision" value="1" onchange="yesnoCheck(1);">Close HR Case</input>
					</label>
					<!--<label class="radio-inline" style='color:#303a46;'>
            <input type="radio" id="decision2" name="decision" value="2" onchange="yesnoCheck(2);">Keep HR Case Open</input>
   </label>-->
				<p class="help-block" id="decError" role="alert"></p>
					</div>
			
			
			</div>
		
		<div class="form-group is-required row" id='commentssection' style='display:none;'>
			<label for="comments" class="col-sm-3 text-right" style="padding-left:1px">
				${gs.getMessage('Additional comments (Customer visible)')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<textarea id="comments" class="col-sm-9 form-control" rows="3" aria-required="true" name="comments"/>	
			</div>
		</div>
		
		<div class="form-group is-required row" id='worknotesection' style='display:none;'>
			<label for="worknotes" class="col-sm-3 text-right" style="padding-left:1px">
				<span class="required-marker"></span>${gs.getMessage('Work Notes')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<textarea id="worknotes" class="col-sm-9 form-control" required="required" rows="3" aria-required="true" name="worknotes" />
				<p class="help-block" id="noteError" role="alert"></p>
			</div>
		</div>
		<input type="hidden" id="selected_decision" name="selected_decision" value="0"/>
		
		<footer id="okCancel" class="modal-footer">
			<input type="hidden" id="task_sys_id" name="task_sys_id" value="${sysparm_sys_id}" aria-hidden="true"></input>
			<input type="hidden" id="task_table_name" name="task_table_name" value="${sysparm_table_name}" aria-hidden="true"></input>
			<input type="hidden" id="selected_service" name="selected_service" value="" aria-hidden="true"></input>
			<button onclick="return submitCancel();" id="cancel" class="btn btn-default">
				${gs.getMessage('Cancel')}
			</button>
			<button id="ok" class="btn btn-primary" onclick="return submitOk(); ">
				${gs.getMessage('Ok')}
			</button>
		 </footer>
	</g:ui_form>
</j:jelly>

Commenting that section looks right.  I am trying to recreate this UI Page and pasted this code in the HTML section and your earlier-posted code in the Client script.  I got an error that </script> is needed below </footer> at the bottom to close out that tag, so try that for starters.  For me to view this UI Page I would need the code for your UI Macro or whatever is causing this UI Page to display.  In that code is likely where you would put or alter the setRedirect line I provided earlier.

Hi @Brad Bowman ,

Thanks for your response . I am proving the complete script for the UI Page including the HTML, Client Script and Processing Script . This is created Human resources Scope.

 

Please suggest.

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 id="transfer_to_it">
		<script src="scripts/heisenberg/heisenberg_all.js" />
		<g:requires name="styles/heisenberg/heisenberg_all.css" includes="true" />
		<j:set var="jvar_sys_id" value="${sysparm_sys_id}" />
		<j:set var="jvar_table_name" value="${sysparm_table_name}" />
		

			<div class="row" style="margin-bottom:10px">
				<div class="col-md-12">
					<p style="font-size: 15px">${gs.getMessage("Select the 'Assignment Group' to transfer this case.")}</p>
				</div>
			</div>
		
		<div class="form-group is-required row">
			
					<label for="assignment_group" class="col-sm-3 text-right" style="padding-left:1px">
						<span class="required-marker"></span>${gs.getMessage('Assignment Group')}
					</label>
					<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
						<g:ui_reference name="assignment_group" value="${jvar_assignment_group}" query="sys_idIN$[gs.getProperty('sn_hr_core.INF_Anx_IT_Groups')]" table="sys_user_group" required="required" />
						<p class="help-block" id="groupError" role="alert"></p>
					</div>
			<label for="decision" class="col-sm-3 text-right" style="padding-left:1px">
				<span class="required-marker"></span>${gs.getMessage('Decision')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<label class="radio-inline" style='color:#303a46;'>
			<input type="radio" id="decision1" name="decision" value="1" onchange="yesnoCheck(1);">Close HR Case</input>
					</label>
					<label class="radio-inline" style='color:#303a46;'>
            <input type="radio" id="decision2" name="decision" value="2" onchange="yesnoCheck(2);">Keep HR Case Open</input>
   </label>
				<p class="help-block" id="decError" role="alert"></p>
					</div>
			
			
			</div>
		
		<div class="form-group is-required row" id='commentssection' style='display:none;'>
			<label for="comments" class="col-sm-3 text-right" style="padding-left:1px">
				${gs.getMessage('Additional comments (Customer visible)')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<textarea id="comments" class="col-sm-9 form-control" rows="3" aria-required="true" name="comments"/>	
			</div>
		</div>
		
		<div class="form-group is-required row" id='worknotesection' style='display:none;'>
			<label for="worknotes" class="col-sm-3 text-right" style="padding-left:1px">
				<span class="required-marker"></span>${gs.getMessage('Work Notes')}
			</label>
			<div class="col-md-7" style="padding-left: 3px;padding-right: 30px">
				<textarea id="worknotes" class="col-sm-9 form-control" required="required" rows="3" aria-required="true" name="worknotes" />
				<p class="help-block" id="noteError" role="alert"></p>
			</div>
		</div>
		<input type="hidden" id="selected_decision" name="selected_decision" value="0"/>
		
		<footer id="okCancel" class="modal-footer">
			<input type="hidden" id="task_sys_id" name="task_sys_id" value="${sysparm_sys_id}" aria-hidden="true"></input>
			<input type="hidden" id="task_table_name" name="task_table_name" value="${sysparm_table_name}" aria-hidden="true"></input>
			<input type="hidden" id="selected_service" name="selected_service" value="" aria-hidden="true"></input>
			<button onclick="return submitCancel();" id="cancel" class="btn btn-default">
				${gs.getMessage('Cancel')}
			</button>
			<button id="ok" class="btn btn-primary" onclick="return submitOk(); ">
				${gs.getMessage('Ok')}
			</button>
		 </footer>
	</g:ui_form>
</j:jelly>

Client Script :

function yesnoCheck(val)
{
	try
	{
		gel('selected_decision').value = val;
		if(val == '1')
		{
			gel('worknotesection').style.display = 'block';
			gel('commentssection').style.display = 'block';
			
		}
		else
		{
			gel('worknotesection').style.display = 'none';
			gel('commentssection').style.display = 'none';
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function valdiateGrpValue()
{
	var finalresult;
	var groupErrorBlock = $j('#groupError');
	var groupValue = gel("assignment_group").value;
	
	if(groupValue == '')
	{
		groupErrorBlock.html(getMessage('Please select a group'));
		finalresult = false;
	}
	else
	{
		groupErrorBlock.html('');
		finalresult = true;
	}
	
	return finalresult;
}

function valdiateDecisionValue()
{
	try
	{
		var finalresult = false;
		var decErrorBlock = $j('#decError');
		var decisions = document.getElementsByName("decision");
		var tlscore = '';
		for (var i = 0, len=decisions.length; i< len; i++)
		{
			if (decisions[i].checked )
			{
				tlscore = decisions[i].value; // if so, hold its value in tlscore
				finalresult = true;
				break; // and break out of for loop
			}
		}
		
		if(finalresult)
		{
			decErrorBlock.html('');
			if(tlscore == '1')
			{
				var notesErrorBlock = $j('#noteError');
				if(gel('worknotes').value == '' || gel('worknotes').value == ' ' || gel('worknotes').value == 'undefined')
				{
					notesErrorBlock.html(getMessage('Please fill Work Notes'));
					finalresult=false;
				}
				else
				{
					notesErrorBlock.html('');
				}
			}
		}
		else
		{
			decErrorBlock.html(getMessage('Please select decision'));
		}
		
		return finalresult;
	}
	catch(e)
	{
		jslog(e);
	}
}

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

function submitOk() {
	var result = $("assignment_group").value != undefined;
	
	if(!valdiateGrpValue())
		{
		result=false;
	}
	
	if(!valdiateDecisionValue())
		{
		result=false;
	}
	
	if (result)
		{
		$('cancel_button').addClassName('disabled');
		$('ok_button').addClassName('disabled');
	}
	
	return result;
}

Processing Script :

(function(_this) {
	var urlOnStack = gs.getSession().getUrlOnStack();
	var originalTask = new GlideRecord(task_table_name);
	if (!originalTask.get(task_sys_id)) {
		gs.addErrorMessage(gs.getMessage("Could not find original case"));
		return;
	}
	
	// Create new Incident from Case
	var inc = new GlideRecord('incident');
	inc.initialize();
	
	// HR Case fields that will carry over to the IT Incident
	
	inc.short_description = originalTask.short_description;
	inc.category = 'Inquiry / Help';
	inc.subcategory = 'Other';
	inc.impact = '4';
	inc.urgency = '3';
	inc.description = originalTask.description;
	inc.assignment_group = assignment_group;
	var worknote = gs.getMessage("Transferred from HR case {0}", [originalTask.number]);
	worknote += '\n\n Work History from HR Case \n\n';
    worknote += originalTask.work_notes.getJournalEntry(-1);
	inc.work_notes = worknote;
	inc.contact_type = 'transfer_hr';
	
	inc.u_email = originalTask.opened_for.email;
	inc.u_email = originalTask.opened_for.phone;
	inc.parent = originalTask.sys_id; //References HR Case from IT Incident form. Update with your custom Incident field or remove this line.
	inc.caller_id = originalTask.opened_for;
	inc.insert();
		GlideSysAttachment.copy(originalTask.sys_class_name,originalTask.sys_id,'incident',inc.sys_id);
		
	var inc_num = inc.number;
	
	var hrcomments = gs.getMessage("This case has been transfered to IT. New incident number is {0}", [inc_num]);
	
	var incLink = '[code]<a target="_blank" href="./incident.do?sys_id='+inc.sys_id+'">'+inc.number+'</a>[/code]';
	
	var hrnotes = gs.getMessage(' Incident Link : {0}', [incLink]);
	
	if(selected_decision == '1')
	{
		hrcomments += '\n\n'+comments;
		hrnotes += '\n\n'+worknotes;
		originalTask.state = '7'; // Cancelled
		originalTask.transferred_to = inc.sys_id;
	}
	
	originalTask.comments = hrcomments;
	originalTask.work_notes= hrnotes;
	
	originalTask.update();
	
	response.sendRedirect(urlOnStack);
			
})(this);