how to open a dialog and pass the data from dialog to parent window

pratapdalai
Tera Contributor

how to open a dialog and pass the data from dialog to parent window

2 REPLIES 2

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

epam
Kilo Guru

Pratap,



PASSING PARAMETERS:



this is very easy to do - you may use cookies for this task. You talking about dialogs - therefore you talking about client-side logic. In this case cookies is very popular mechanism to use.



1 - STEP - put data into cookie on 1st page



document.cookie="chosen="+value;



2 - STEP - retrieve data from cookie on another page/window



When you put data from one window/dialog into cookie, then you get get it using, for example, similar logic:




//prepare variable to get value from cookie


var myData = '';



//read all values from cookie


var coo_str = document.cookie;



//split values into array


var coo_arr = coo_str.split(";");



var tmp = null;



//running through array until find our data


var coo_str = document.cookie;


var coo_arr = coo_str.split(";");


var tmp = null;



for(var i=0; i<coo_arr.length; i++) {


  tmp = coo_arr[i].split("=");


  if(tmp[0].trim() === 'chosen') { // in this example - we looking for variable named "chosen"


            myData = tmp[1].trim();


  break;


}


}



RENDERING DIALOG WINDOW:



Assuming you decide to render from UI Action:


var gdw = new GlideDialogWindow('incident_display_list');


gdw.setTitle('Parent Incident');


gdw.setPreference('table', 'incident_list');


gdw.setPreference('title', 'A New Title');


var query = 'active=true^sys_idIN'+param;


sid = param.split(",");


gdw.setPreference('sysparm_query', query);


gdw.render();



Wiki&Community have some good basics on this as well: