Pass values when calling a GlideDialogForm with a UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2010 03:33 PM
Im working on a UI Action that calls up a GlideDialogForm from a Catalog Task. Im using a bit of code I found here:
http://www.servicenowguru.com/system-ui/glidedialogwindow-quickforms/
function showMyForm(){
//Get the table name and sys_id of the record
var tableName = "u_token_transaction";
var tasknum = g_form.getValue('current.number');
var reqcust = g_form.getValue('current.u_requested_for');
//Create and open the dialog form
var dialog = new GlideDialogForm('Assign Token', tableName); //Provide dialog title and table name
dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record
dialog.addParm('sysparm_view', 'AssignToken'); //Specify a form view
dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
dialog.render(); //Open the dialog
}
Heres my problem- I want to pass a couple values from the current form into the Assign Token form when it is launched. I cant find any documentation that specifies the syntax and none of my guesses seem to work. I want something that is the equivalent of
dialog.setValue('u_task_number', tasknum); (which of course doesnt work).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2012 01:12 PM
I think I have the same problem. Cannot push form data to popup in IE but can see it in FireFox/Chrome. setReadOnly is also not working in IE but works in FireFox/Chrome. We are also Berlin.
Is this a bug?
Thanks,
Sherard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2013 05:18 AM
The following fragment:
dialog.setLoadCallback(function(iframeDoc) {
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.setValue('po_number', po);
...
dialogFrame = null;
});
dialog.render(); //Open the dialog
Can be fixed with the following code (by waiting until the GlideForm object is available):
dialog.setLoadCallback(function(iframeDoc) {
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
var interval;
var count = 0;
interval = setInterval(function() {
try {
if (dialogFrame.g_form) {
dialogFrame.g_form.setValue('po_number', po);
clearInterval(interval);
dialogFrame = null;
} else if (count > 50) {
clearInterval(interval);
dialogFrame = null;
}
}catch (e) {
clearInterval(interval);
dialogFrame = null;
}
count++;
}, 200);
});
dialog.render(); //Open the dialog
I suspect that the speed of browsers like Chrome mean that they do not exhibit the issue. I have raised a problem for someone to implement a fix that ensures that the GlideForm object (g_form) is available when the load callback function is called. This solution can be used until then, and should still work after the fix is implemented.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2012 12:18 PM
It looks like the form is now rendered differently, and we will need to delay the execution of the script, by adding it to the list of callback handlers executed when the form has been rendered (via
).
addLoadEvent
If we take the previous example
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.setValue('u_requested_by', reqcust);
dialogFrame.g_form.setValue('u_task_number', tasknum);
});
You'll need to put all the logic into the callback function, like so:
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.addLoadEvent(function() {
dialogFrame.g_form.setValue('u_requested_by', reqcust);
dialogFrame.g_form.setValue('u_task_number', tasknum);
});
});
Note, this does highlight that using anything which is not part of the published API should be considered with extreme caution. Try to find a different solution if at all possible, as undocumented methods form part of the internal codebase, and may be changed/refactored between releases. In this case, it is possible to:
- Populate values by passing an encoded query passed to the
parameter using
sysparm_query
, for example,
dialog.addParm
dialog.addParm('sysparm_query', 'short_description=' + g_form.getValue('short_description')); - Remove the extra fields by creating a custom view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2012 02:19 PM
Thanks Chris,
A question related to your last response using sysparm_query. How could you also make those same fields readOnly using the sysparm_query versus using the callback function?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2012 10:55 AM
However, given your parting admonition, I'm going back to my client with a suggestion that we redesign our function so that it doesn't rely on a dialog window. In this case we will use a related list to add the items that should be associated with the record currently displayed on the form. I can use UI Policies on a custom view of the related record form to hide unneeded fields and g_form.getReference (with a callback function, of course) or a GlideAjax call to a script include to get information from the current record which I need to insert into the related record. All of that can be done with officially documented functionality, without the need to use a custom dialog.