- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 08:18 AM
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>
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 02:53 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 08:22 AM
Issue in your current script is pop is loading without waiting for model value. To get around with that instead of getReference in UI action, try using GlideAjax with getXMLWait() to wait till the value of the model is received and then load the pop up
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 08:39 AM
hi dvp, please correct my code if any thing wrong, i am getting ga.getAnswer() alert as "null"
please find my script include:
var TogetModelName = Class.create();
TogetModelName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getmodel: function() {
var sysId = this.getParameter('cmdb_ci');
var model = new GlideRecord( 'cmdb_model' );
model.addQuery('sys_id',sysId);
model.query();
if( model.next() ){
modelname = model.display_name;
}
return modelname;
},
type: 'TogetModelName'
});
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);
// }
}
var ga = new GlideAjax("TogetModelName");
ga.addParam("sysparm_name", "getmodel");
ga.addParam("cmdb_ci", modelidsysid );
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 08:45 AM
Please try the below script include
var TogetModelName = Class.create();
TogetModelName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getmodel: function() {
var sysId = this.getParameter('cmdb_ci');
var model = new GlideRecord( 'cmdb_ci' );
model.addQuery('sys_id',sysId);
model.query();
if( model.next() ){
modelname = model.model_id.display_name;
}
return modelname;
},
type: 'TogetModelName'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2019 08:47 AM
not working still it throws alert as null