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

SanjivMeher
Kilo Patron
Kilo Patron

Refer below link. The call back function runs only after submission.



GlideModalForm



Please mark this response as correct or helpful if it assisted you with your question.

I'm not talking about the onCompletionCallback function, I'm talking about the onLoadCallback function. Two different things as you can read onhttps://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_GlideModalFormV3API



onLoadCallback:


The function to be called after the form has been loaded. The callback function has the form


callBackFunction(GlideModalForm obj)



onCompletioCallback:


The callback function that you provided to be called when the form has been successfully processed. The callback function has the form


callBackFunction(GlideModalForm obj)



Check below link.



Pass values when calling a GlideDialogForm with a UI Action



Try adding this code before your




  1. 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;
});

Please mark this response as correct or helpful if it assisted you with your question.

  • setLoadCallback method is not available on GlideModalForm
  • The parameter of setOnloadcallback is a GlideModal Object that has no defaultView or parentWindow property


The Parameter of setOnloadcallback has the following properties for example



{"preferences":{"table":"problem","renderer":"RenderForm","type":"direct","sys_id":-1},"id":"problem","backdropStatic":false,"size":"modal-95","tableName":"problem","title":"Create Problem","$window":{"0":{"jQuery18202753499171590975":1816,"_prototypeUID":31},"length":1},"_bodyHeight":629.8833312988281}



Sow how will I reach the g_form object from this GlideModal Property? Maybe somehow via $window?




The following example does not work.





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


      d.setOnloadCallback(someFunction);


      d.setSysID(-1);



someFunction(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;



}