- 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-04-2021 10:10 PM
Is the client script type OnSubmit. If so, remove g_form.save().
Use it only for Onchange Client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 10:33 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 10:38 PM
Can you please explain your use case? why and when you want to save form?
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2021 06:35 AM
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.