Client script to automatically reload and save/submit the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 12:59 AM
Hello. I'm struggling with a client script which would automatically reload and save/submit the new form. Reason for that is, we have a need to display a related list on the form right when you open it. Since the record has to be inserted in the database for the related list to appear, I'm not sure what other workarounds can there be (business dont want to manually save the form when they open it with UI action).
1. I tried using g_navigation.reloadWindow(); and location.reload();, but that keeps reloading the form non-stop. How can I make it to reload the form only one time?
2. How can I make the form to be inserted in the database afterwards? I tried using g_form.submit(); and g_form.save();, but that didnt help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 01:16 AM
Hi,
In point 1:
Try adding a validation:
if(g_form.isNewRecord()){ - this will evaluate if it's a new record.
continue with the logic here
}
Hope this helps!
Tudor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:43 AM
Thanks, but that didnt help. The form still stucks in a reloading loop and the related list does not appear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 04:28 AM
Found my issue. That form didnt have an insert and stay UI action, therefore g_form.submit() didnt work. Created UI action with action name 'sysverb_insert_and_stay' as 'Form context menu' and wrote the below client script:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.isNewRecord()) {
g_form.submit('sysverb_insert_and_stay');
}
}
Now it automatically inserts the record to the table and loads the needed related list.