g_form.save() command causing looping behavior

Dom G
Tera Expert

The g_form.save() in the below client script is causing looping behavior. Any suggestion on how to correct this?

Thank you..

 

var opened_by;
var requested_for;

requested_for = g_form.getValue('requested_for').toString();
opened_by = g_form.getValue('opened_by').toString();

if (opened_by != requested_for) {
//alert('hello');
g_form.setValue('watch_list', g_form.getValue('watch_list').toString() + ',' + g_form.getValue('opened_by').toString());
g_form.save();

1 ACCEPTED SOLUTION

Why don't you write display Business rule to set Value?

You can setValue while form is displayed to end user and it will save the value to backend.

find_real_file.png

 

In script you can use:

find_real_file.png

 

(function executeRule(current, previous /*null when async*/) {
	
if(current.watch_list.toString().indexOf(current.opened_by.toString())<0){
	current.watch_list = current.watch_list+','+current.opened_by;
	current.update();
}

})(current, previous);

 

Using current.update(); in business rule is not recommended but you can use it in display BR. It will not impact performance as this BR only works when form is being displayed, so it will not make recursive call. 

 

This way you can achieve the same results.

if you have observed g_form.save() saves the form but the values are not being saved that's why checking opened_by in watchlist was not working. g_form.save() workes in UI Action and UI pages.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

9 REPLIES 9

AnirudhKumar
Mega Sage
Mega Sage

Is the client script type OnSubmit. If so, remove g_form.save().

Use it only for Onchange Client scripts

Dom G
Tera Expert

No, it's  onload. . 

 

i could try running it onchange, but not sure on which field to run it on, so to trigger the script.

 

 

 

 

Can you please explain your use case? why and when you want to save form?

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

If "opened by" is different  than "requested for" then I want to add "opened by" to the watchlist.

I do this by running an onload client script and the form needs to be saved there.