g_form.save, g_form.submit and gsft method I am saving form but the form is loading again and again

Komaldeep
Tera Contributor

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();
}
}

12 REPLIES 12

@Ankur 
This is the code I wrote in script include - 
get_ProjectName: function() {
var res;
var user = this.getParameter('sysparm_usr');
var gr_pro = new GlideRecord('u_project_details_combination');
gr_pro.addQuery('u_project_number', user);
gr_pro.query();
if (gr_pro.next()) {
res = gr_pro.getValue('u_project_name').toString();
}
return res;
},
Thanks

@Komaldeep 

your BR will be looking like this

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr_pro = new GlideRecord('u_project_details_combination');
	gr_pro.addQuery('u_project_number', current.u_project_number);
	gr_pro.query();
	if (gr_pro.next()) {
		res = gr_pro.getValue('u_project_name').toString();
	}
	current.u_project_name = res;

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,
I am not able to get the solution with the respective code.
Thank you

@Komaldeep 

Glad to know that my script helped.

Please mark my response as correct and helpful to close the thread

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Swapnil Shirsik
Giga Guru

You can try by removing g_form.save();