g_form.save, g_form.submit and gsft method I am saving form but the form is loading again and again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 12:12 AM
Hello Everyone,
I want to thank you all in advance.
I am facing issue while using g_form.save(), g_form.submit(); and gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay'); method
The requirement is to save the record coming from the script include everything is working fine but when I am trying to save my record in the onchange client script with the above method the form is getting loaded again and again for me.
Here is the code I wrote -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga_project = new GlideAjax('sn_hr_core.ProjectDetailsPosition');
ga_project.addParam("sysparm_name", "get_ProjectName");
ga_project.addParam('sysparm_usr', g_form.getValue('u_project_number'));
ga_project.getXML(getCal);
function getCal(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_project_name', answer);
g_form.save();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 12:41 AM
Hello,
Why are you trying to save the code. Don't use g_form.save(); at the end. Let the use submit/save after making the change on the field.
If you use g_form.save it will work as a normal save/submit works where the form is saved and loaded.
If the user selects a wrong value in the onchange field and wants to correct it he has to wait till the form saves which is not a good user experience.
I would suggest to remove the g_forom.save() in the script
Let the user himself submit when he wants to.
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 12:44 AM
Hi,
using the isLoading should stop the script from running again and again.
what debugging have you done?
Why are you saving the form using client script?
Why not use before insert/update BR and since you already having logic to get the value using script include?
you can directly use BR and no client script is required.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 10:11 PM
Hello Ankur,
how can I write in br onchange of project number? and value should get clear on changing and new value should get updated can you help me with the sample code if possible?
Thank and Regards
Komal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 11:06 PM
You can start with the Before update BR
Condition: current.u_project_number.changes() && current.u_project_number != ''
Script:
// you can invoke the script include function or directly write the logic in BR
If possible share the script include function code here if you require help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader