GlideModalForm

amkatulak
Giga Expert

Hi,

I'm trying to use the new GlideModalForm API and I'm not sure exactly how to utilize the callback function.

Here is my UI Action.   Basically I need to open a form to create a new related record to my original table.   Once I hit submit, I want the original form that the UI action was initiated from to refresh so that my new item appears in the related list.

function openBidPop() {

  var bid = new GlideModalForm('New Bid','x_ahho_fm_chargeba_bid_matrix',someCallBack());

  bid.addParm('sysparm_request',g_form.getUniqueValue());

  bid.render();

}

function someCallBack() {

   

}

Thanks in advance!

1 ACCEPTED SOLUTION

I was able to get my desired result by using the .setCompletionCallback method and then calling g_form.save() from the function.


Thanks



function openBidPop() {


  var bid = new GlideModalForm('New Bid','x_ahho_fm_chargeba_bid_matrix');


  bid.addParm('sysparm_request',g_form.getUniqueValue());


  bid.render();


  bid.setCompletionCallback(refreshForm);



}


function refreshForm() {


  g_form.save();


}


View solution in original post

3 REPLIES 3

lorisd_avanzo
ServiceNow Employee
ServiceNow Employee

As per the documentation, the call back function is The function to call after the form has been submitted and processed on the server


In your case you would just need to refresh the page in order to get (in the original form) the related list updated with the new inserted record via GlideModalForm.



You basically need the below code in your someCallBack() function:


function someCallBack(){


        window.location.reload(true);


}



I hope this helps.



Best Regards,


Loris


Hi, thanks, but when I add that, I'm getting an error TypeError: Cannot read property 'location' of null(…)


This is a scoped app, don't know if that has anything to do with this or not.


I was able to get my desired result by using the .setCompletionCallback method and then calling g_form.save() from the function.


Thanks



function openBidPop() {


  var bid = new GlideModalForm('New Bid','x_ahho_fm_chargeba_bid_matrix');


  bid.addParm('sysparm_request',g_form.getUniqueValue());


  bid.render();


  bid.setCompletionCallback(refreshForm);



}


function refreshForm() {


  g_form.save();


}