how to pass uiaction value to ui page

Deepthi13
Tera Expert

hi team,

pls find below code, from ui action i am passing 2 values to ui page

dialog.setPreference("commentstext", requestfor); //Pass in comments for use in the dialog
dialog.setPreference("modeldisplayname", modelname); //Pass in short description for use 

commentstext is working fine, but modelname value is not printing please suggest.

 

ui action:

function commentsDialog() {
//Get the values to pass into the dialog
var modelidsysid = '';
var modelname = '';
var requestfor = g_form.getDisplayBox("requested_for").value;//Initialize and open the Dialog Window
var ci = g_form.getReference('cmdb_ci',doAlert); // doAlert is our callback function
function doAlert(ci) { //reference is passed into callback as first arguments
modelidsysid = ci.model_id;
var model = new GlideRecord('cmdb_model');
model.addQuery('sys_id',modelidsysid);
model.query();
alert('outsideif' + modelidsysid);
if(model.next()){
modelname = model.display_name;
alert(modelname);
}
}
alert(modelname+ 'is model name');
var dialog = new GlideDialogWindow("task_comments_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
dialog.setSize(1250,500);
dialog.setTitle("Add Task Comments"); //Set the dialog title
dialog.setPreference("commentstext", requestfor); //Pass in comments for use in the dialog
dialog.setPreference("modeldisplayname", modelname); //Pass in short description for use in the dialog
dialog.adjustBodySize();
dialog.render(); //Open the dialog
}

ui page:

<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_commentstext"
expression="RP.getWindowProperties().get('commentstext')" />
<g:evaluate var="jvar_modeldisplayname"
expression="RP.getWindowProperties().get('modeldisplayname')" />

<!-- Set up form fields and labels -->
<div class="task-comment-dialog-container">
<table width="90%" class="">
<tr id="description_row" valign="top">
<td colspan="2">
<!-- Short description value used as a label -->
${jvar_commentstext}
${jvar_modeldisplayname}
</td>
</tr>

1 ACCEPTED SOLUTION

There was a typo in the earlier code

function commentsDialog() {
	//Get the values to pass into the dialog
	var modelidsysid = '';
	var modelname = '';
	var requestfor = g_form.getDisplayBox("requested_for").value;//Initialize and open the Dialog Window
	var ci = g_form.getValue('cmdb_ci');
	
		var ga = new GlideAjax("TogetModelName");
		ga.addParam("sysparm_name", "getmodel");
		ga.addParam("cmdb_ci", ci );
		ga.getXMLWait();
		alert( ga.getAnswer() );
	
		// alert(modelname+ 'is model name');
		var dialog = new GlideDialogWindow("task_comments_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
		dialog.setSize(1250,500);
		dialog.setTitle("Add Task Comments"); //Set the dialog title
		dialog.setPreference("modeldisplayname", modelname);
		dialog.setPreference("commentstext", requestfor); //Pass in comments for use in the dialog
		dialog.adjustBodySize();
		dialog.render(); //Open the dialog
	}

 

I just tested in my personal instance and i was able to see the model in pop up.

View solution in original post

9 REPLIES 9

In the ui action please update the code as follows

 

function commentsDialog() {
	//Get the values to pass into the dialog
	var modelidsysid = '';
	var modelname = '';
	var requestfor = g_form.getDisplayBox("requested_for").value;//Initialize and open the Dialog Window
	var ci = g_form.fetValue('cmdb_ci');
	
		var ga = new GlideAjax("TogetModelName");
		ga.addParam("sysparm_name", "getmodel");
		ga.addParam("cmdb_ci", ci );
		ga.getXMLWait();
		alert( ga.getAnswer() );
	
		// alert(modelname+ 'is model name');
		var dialog = new GlideDialogWindow("task_comments_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
		dialog.setSize(1250,500);
		dialog.setTitle("Add Task Comments"); //Set the dialog title
		dialog.setPreference("modeldisplayname", modelname);
		dialog.setPreference("commentstext", requestfor); //Pass in comments for use in the dialog
		dialog.adjustBodySize();
		dialog.render(); //Open the dialog
	}

hi dvp,

now i got alert correctly but in my ui page it is not showing still

<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_commentstext"
expression="RP.getWindowProperties().get('commentstext')" />
<g:evaluate var="jvar_modeldisplayname"
expression="RP.getWindowProperties().get('modeldisplayname')" />

<!-- Set up form fields and labels -->
<div class="task-comment-dialog-container">
<table width="90%" class="">
<tr id="description_row" valign="top">
<td colspan="2">
<!-- Short description value used as a label -->
${jvar_commentstext}
${jvar_modeldisplayname}
</td>

There was a typo in the earlier code

function commentsDialog() {
	//Get the values to pass into the dialog
	var modelidsysid = '';
	var modelname = '';
	var requestfor = g_form.getDisplayBox("requested_for").value;//Initialize and open the Dialog Window
	var ci = g_form.getValue('cmdb_ci');
	
		var ga = new GlideAjax("TogetModelName");
		ga.addParam("sysparm_name", "getmodel");
		ga.addParam("cmdb_ci", ci );
		ga.getXMLWait();
		alert( ga.getAnswer() );
	
		// alert(modelname+ 'is model name');
		var dialog = new GlideDialogWindow("task_comments_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
		dialog.setSize(1250,500);
		dialog.setTitle("Add Task Comments"); //Set the dialog title
		dialog.setPreference("modeldisplayname", modelname);
		dialog.setPreference("commentstext", requestfor); //Pass in comments for use in the dialog
		dialog.adjustBodySize();
		dialog.render(); //Open the dialog
	}

 

I just tested in my personal instance and i was able to see the model in pop up.

Thanks!

not working still it throws alert as null, can you please see ui action once if i am assigning correctly or not