Saving or Updating a field value in the table and on the fly without reloading form view

darshan3
Giga Contributor

We have a tabbed form view having 5 tabs. Each tabs are having different fields. 

We have a use case if a "Apply Default" button clicked on form it will save default value of that particular field on table and redirect back to same tab.

Issue here is when we click on "Apply Default" it is refreshing form view (Not browser window) and removing entered values of other fields. 

Is there any way we can save default values of a field on the fly without refreshing form view?

We have tried g_form.save() and g_form.submit() but both seem to refresh the form view.

Here is the code written on "onClick" event of "Apply Default" button. 

function applyDefaults() {
    var profileSysId = g_form.getUniqueValue();
    var ga = new GlideAjax("ClientCallableGlideAJAX");
    ga.addParam("sysparm_name", "applyDefaultsInProfile");
    ga.addParam("sysparm_profileSysId", profileSysId + "");
    ga.addParam("sysparm_profileSection", "incident_creation");
    ga.getXML();
    setStep(2);
    gsftSubmit(gel("apply_default_reload"));
}


  Here is code written in script of  "apply_default_reload" UI action.

gs.setRedirect(current.getLink(true));

4 REPLIES 4

palanikumar
Mega Sage

Hi,

What are you doing with GlideAjax?

If you are storing the form values to the actual record using ajax call then gsftSubmit function call is not required.

Thank you,

Palani

Thank you,
Palani

Thanks for the reply

In GlideAjax we are setting default value of field and updating record like this. 

profileGr.setValue("incident_creation_criteria","severity>=7");
profileGr.setValue("apply_incident_creation_criteria",true);
profileGr.update();

Issue with removing gsftSubmit is that we have used custom UI macro to select multiple values and those values are getting stored in 
Servicenow string field as JSON. And when page reloads we populating saved data using Jquery on document.ready()
Therefore We can't remove gsftSubmit call.

$j(document).ready(function () { 
    //Code of dom manipulation and setting values of HTML elements 
});

find_real_file.png

Yousaf
Giga Sage

Hi,

Please refer to this link i hope it helps.

How to prevent page reload in UI Action

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

darshan3
Giga Contributor

Thanks for the reply, 

We have gone through the above thread. It is not we wanted. Thread says about how we can call Server side code (Business Rule) and Client side code both  from "Client" UI action using gsftSubmit 

and as @Chuck Tomasi mentioned UI action do a form reload.

Which we don't want as we have used custom UI macro to select multiple values and those values are getting stored in 
Servicenow string field as JSON. And when page reloads we populating saved data using Jquery on document.ready()
Therefore We can't remove gsftSubmit call as well.  

Screenshot: Field populated using UI macro on document.ready()

find_real_file.png