- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 10:02 PM
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();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2021 10:30 PM
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.
In script you can use:
(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
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2021 06:44 AM
As suggested by AnirudhKumar, you can remove the g_form.save(); from onload client script. As it is onLoad and saving right after loading the form automatically will be recursive.
An alternative way is to apply save only when watchlist is updated.
Modify your logic as given below:
if (opened_by != requested_for) {
var watch_list = g_form.getValue('watch_list).toString();
if(watch_list.indexOf(opened_by)<0){
//alert('hello');
g_form.setValue('watch_list', g_form.getValue('watch_list').toString() + ',' + g_form.getValue('opened_by').toString());
g_form.save();
}
}
This way it will save your form only once if. If user is aleready added to watch list then it will not call g_form.save() again.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2021 06:15 PM
Hi Anil,
Thanks for the suggestion. That was a good idea. But it didn't work. It's still behaving the same way.
I'm not sure I understand, though. you're telling me to remove the g_form.save() from the onload client script. Then, how should I run it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2021 10:30 PM
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.
In script you can use:
(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
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 10:39 PM
Cool. If it's onload, still remove the g_form.save().
What will happen is this.
Form loads -> System sets the value on form (But its not saved back-end, but that's ok) -> After user works with the form, he has to save it by clicking submit/save -> That will cause the value you set to be saved back-end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 01:10 PM
When you save a form, you load the form again, hence the looping.