How to get access to g_form of record opened by GlideModalFormV3

Niclas
Giga Guru

With GlideModalForm v3 it is possible to open a form in an overlay content dialog. GlideModalForm is also featuring a onloadCallbackfunction. How can we gain access to the g_form of the record object that has been opened by the GlideModaWindow

Example:

Lets say we have a "Create Problem" button on the Incident Form that opens a GlideModalForm:

var d = new GlideModalForm("Hello World", "problem");

      d.setOnloadCallback(someFunction);

      d.setSysID(-1);

someFunction(oGlideModal) {

    g_form.addInfoMessage("By submitting this Problem you will set the Incident to Pending Incident");

==> This g_form Object is still pointing to the Incident Record. How to point to the g_form Object of the Problem?

}

1 ACCEPTED SOLUTION

It seems like GlideModalForm is rendering a Bootstrap Modal in a frame called "dialog_frame". The access to the g_form object in the rendered Modal is possible via window.frames["dialog_frame"].g_form



For Example if you open a GlideModalForm to create a new problem from an Incident, you can Access the Problem and Incident Values in the onLoadcallback as followed. The only thing that does not seem to work with GlideModal is g_form.addInfoMessage() and g_form.addErrorMessage();



var d = new GlideModalForm("Create Problem", "problem");


d.setOnloadCallback(showInfoOnProblem);


d.setSysID(-1);


d.render();



function showInfoOnProblem(oGlideModal) {


var oModalGForm = window.frames["dialog_frame"].g_form;


alert(g_form.getValue("number")); //Alerts the Incident numer


alert(oModalGForm .getValue("number")); //Alerts the Problem Number


g_form.showFieldMsg("number", "This message is shown on the Incident form under the number field");


oModalGForm.showFieldMsg("number", "This Message is shown on the Create New Problem Modal under the number field");


g_form.showInfoMessage("This message is shown on the Incident form");


oModalGForm.showFieldMsg("number", "Info Messages an Modals do not seem to work");


}


View solution in original post

11 REPLIES 11

It seems like GlideModalForm is rendering a Bootstrap Modal in a frame called "dialog_frame". The access to the g_form object in the rendered Modal is possible via window.frames["dialog_frame"].g_form



For Example if you open a GlideModalForm to create a new problem from an Incident, you can Access the Problem and Incident Values in the onLoadcallback as followed. The only thing that does not seem to work with GlideModal is g_form.addInfoMessage() and g_form.addErrorMessage();



var d = new GlideModalForm("Create Problem", "problem");


d.setOnloadCallback(showInfoOnProblem);


d.setSysID(-1);


d.render();



function showInfoOnProblem(oGlideModal) {


var oModalGForm = window.frames["dialog_frame"].g_form;


alert(g_form.getValue("number")); //Alerts the Incident numer


alert(oModalGForm .getValue("number")); //Alerts the Problem Number


g_form.showFieldMsg("number", "This message is shown on the Incident form under the number field");


oModalGForm.showFieldMsg("number", "This Message is shown on the Create New Problem Modal under the number field");


g_form.showInfoMessage("This message is shown on the Incident form");


oModalGForm.showFieldMsg("number", "Info Messages an Modals do not seem to work");


}


brnunn
Tera Contributor

Awesome - thanks for shedding light on this as the documentation is severely lacking. GlideDialog is a very useful utility - not sure why this isn't championed more. 

 

Thanks!

tonyfleming
Kilo Contributor

Bringing this up again.   The correct answer here does not work for me.   I am getting the error that the frames object is not defined in the browser console.   I figure this should be pretty straight forward and am suprised there isn't more documentation on how to access the form, seeing as you could do it pretty easily with the GlideDialogForm object.   Any ideas?


Hi Tony,



The solution provided by me is for GlideModalForm. GlideDialogForm is a different class. I would suggest to use GlideModalForm as it is described as re-worked GlideDialog and GlideDialogForm is not documented at all.


marcguy
ServiceNow Employee
ServiceNow Employee

Hopefully you got this resolved but I managed to populate the Modal by adding sysparm_query...

 

d.addParm('sysparm_query', 'tasks='+g_form.getUniqueValue()+'^task_table='+g_form.getTableName()); // populate fields