Pass values when calling a GlideDialogForm with a UI Action

sreed
Kilo Explorer

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).

18 REPLIES 18

As far as the browser can tell, the background form and the new GlideDialog are two entirely separate windows--in general, there isn't a way for the two to communicate.

The last thing I would suggest to try is to save the items you're looking for in global variables, instead of local ones.

So in the script, instead of doing setting a term without the "var" like this:



var myVar = g_form.getValue('my_field');

Try:


myVar = g_form.getValue('my_field');


This should theoretically create a "global" variable (to make sure it doesn't overwrite anything else, prepend it with "u_"). The only unknown is if "global" is in scope within the new dialog window.

Then, you'd have to write a client script for your glide dialog form to pull those global variables out of memory.


Chris_Hann
ServiceNow Employee
ServiceNow Employee

Hi sreed,

Try adding this code before your


dialog.render
, make sure you change the field names if you need to:

<pre>

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);
dialogFrame = null;
});


I have only been able to test this out in FF and Safari, if you are using IE, let me know how you go 🙂


Fabulous! Worked fine in both firefox and IE.


This is awesome! Nice work figuring this out. I've updated the SNCGuru.com article referenced above to include this tip.


Hi Mark, Chris, et al,

We've used the information in this article as well as Mark's SNC Guru article on GlideDialog Quick Forms to create a dialog form that updates records in our cmdb_ci_computer table with Purchase Order information that has been entered in another form. The solution has been working like a charm since we implemented it several months ago.

We just upgraded one of our instances to Berlin Hot Fix 2. Since the upgrade, the information from the Purchase Order form is no longer being passed to the dialog form in IE (it is still working as expected in Google Chrome). Additionally, the UI action which renders the glide dialog form hides many of the fields on the form before rendering it. This portion of the UI Action script is also not working when using IE in Berlin.

Here is the configuration for our UI Action.

Name: Add Computer to Inventory
Table: Asset Reciept [u_asset_receipt]
Action Name: Add Workstation
Active: True
Show insert: True
Show update: True
Client: True
Form button: True
Form context menu: True
Onclick: showMyForm();
Condition: !current.isNewRecord()
Script:



function showMyForm(){
var tableName = 'cmdb_ci_computer'; //specify the table for the Glide Dialog form
//Get values from the Asset Receipt table
var po = g_form.getValue('u_po_number');
var bu = g_form.getValue('u_business_unit');
var mfgr = g_form.getValue('u_manufacturer');
var model = g_form.getValue('u_model');
var chassis = g_form.getValue('u_chassis');
var invLoc = g_form.getReference('u_inventory_location').sys_id;
var hwSubStatus = g_form.getValue('u_hardware_substatus');

//Create and open the dialog form
var dialog = new GlideDialogForm('Add a Workstation to Inventory', 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', 'add_inventory'); //Use the Add Inventory view of the form
dialog.addParm('sysparm_form_only', 'true'); //Remove related lists

//Callback inserts values into the Computer record after data are returned from the server
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('po_number', po);
dialogFrame.g_form.setValue('u_bu_funding', bu);
dialogFrame.g_form.setValue('manufacturer', mfgr);
dialogFrame.g_form.setValue('model_number', model);
dialogFrame.g_form.setValue('form_factor', chassis);
dialogFrame.g_form.setValue('location', invLoc);
dialogFrame.g_form.setValue('hardware_substatus', hwSubStatus);

//Hide most of the fields so they don't appear on the form
dialogFrame.g_form.setDisplay('manufacturer', false);
dialogFrame.g_form.setDisplay('model_number', false);
dialogFrame.g_form.setDisplay('po_number', false);
dialogFrame.g_form.setDisplay('hardware_substatus', false);
dialogFrame.g_form.setDisplay('form_factor', false);
dialogFrame.g_form.setDisplay('location', false);
dialogFrame.g_form.setDisplay('u_bu', false);
dialogFrame = null;
});
dialog.render(); //Open the dialog
}


So, it appears that after the Berlin upgrade, the Callback function isn't working. Any thoughts on how I might go about restoring the functionality we had under Aspen?