UI Action Server Side to get values from Client

Community Alums
Not applicable

Hi all,

I've checked numerous articles but cannot find a solution that would suit me.

What I am trying to do is to create a UI action that would give me a pop-up window for user selection and then take the value for use in server side in order to determine which view should be used and this is what I came up with until now but I cannot get the value in the server script at any way:

UI ACTION:

var companyName;
var dialog;
function openWindow(){
	dialog = new GlideDialogWindow("test_pop");
	dialog.render();
}

function getCompany(company){
	g_list.setGroupBy(company);
	dialog.destroy();
	g_list.action("SOME ACTION ID", "sysverb_new");
}

if (typeof window == 'undefined') {
    run();
}

function run(){
	gs.addInfoMessage(current.company);
	if (gs.hasRole('itil,sn_incident_write')) {
		var view = "";
		if(companyName === "SOME COMPANY ID"){
			view = "SOME VIEW NAME";
		} else {
			view = "SOME VIEW NAME";
		}
		var test = 'incident.do?sysparm_view=ofsted&sysparm_view_forced=true';//sysparm_view= would be a variable
		action.setRedirectURL(test);
	}
}

UI PAGE XML

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<html>
		<body>
		Company Name: <g:ui_reference name="company" id="company" table="core_company" completer="AJAXTableCompleter" query="active=true"/>
		<g:dialog_buttons_ok_cancel ok="validateComments()"/> 
		</body>
	</html>
</j:jelly>

UI PAGE CLIENT SCRIPT

function getCompanyValue() {
//Gets called if the 'OK' dialog button is clicked
//Make sure dialog comments are not empty
var name = gel("company").value;
	name = trim(name);
if (name == "") {
//If comments are empty stop submission
alert("Please provide company to proceed.");
return false;
} else {
//If comments are not empty do this...
	getCompany(name);
}
}
1 ACCEPTED SOLUTION

Periyasamy P
Tera Guru

Its better to write your server code in UI page processing script. Instead of UI action.

 

         gs.addInfoMessage(company);
	if (gs.hasRole('itil,sn_incident_write')) {
		var view = "";
		if(company === "SOME COMPANY ID"){
			view = "SOME VIEW NAME";
		} else {
			view = "SOME VIEW NAME";
		}
		var test = 'incident.do?sysparm_view_forced=true&sysparm_view='+view+"&sys_id"+sys_id;//sysparm_view= would be a variable
		response.setRedirectURL(test);
	}

View solution in original post

3 REPLIES 3

Periyasamy P
Tera Guru

Its better to write your server code in UI page processing script. Instead of UI action.

 

         gs.addInfoMessage(company);
	if (gs.hasRole('itil,sn_incident_write')) {
		var view = "";
		if(company === "SOME COMPANY ID"){
			view = "SOME VIEW NAME";
		} else {
			view = "SOME VIEW NAME";
		}
		var test = 'incident.do?sysparm_view_forced=true&sysparm_view='+view+"&sys_id"+sys_id;//sysparm_view= would be a variable
		response.setRedirectURL(test);
	}

Community Alums
Not applicable

hello,

instead of redirecting to the link, it keeps opening the UI Page itself - please see pictures

Community Alums
Not applicable

I used response.sendRedirect instead and it worked. thank you!