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

Usually you can do this with sysparm_query, but there will be problems with date fields.

 

d.addParam('sysparm_query', "date_field' = g_form.getValue("my_date_field"));

 

If the Session Date Format is for example dd.MM.YYYY this would cause something like

date_field="30.01.2015" and this can not be handled by the parameter as it expects the internal format (mm-dd-YYYY)

 

mak1A4
Tera Guru

I also stumbled upon this problem and managed to find a way to get the g_form object in the callback function (madrid).

https://community.servicenow.com/community?id=community_article&sys_id=32cede41db85f38013b5fb2439961...