auto-save a new record in a form with UI Policy?

woodyfairley
Tera Guru

This is not a question, just sharing a solution (although it is still sloppy in execution). I have been struggling with a complicated form (well, complicated for me) that incorporates list views from two tables in the form: I developed a GlideDialogForm that pops up with a UI Action button for each of the other tables, from the original form, but to populate the list view in the original form it had to be saved (the record had to exist because it held reference fields for the other two tables).

After weeks of searching, copying and pasting code, testing and corrupting whole tables, and dreaming in code, today I found this thread and copied the line to my notepad full of script scraps.

How to save the form using ui action in client script?

Alberto replied with a short line of code that triggered my interest so I copied it, and later tonight after a hundred other searches, I was reading about UI Policies in the docs pages here  t_createAUIPolicy.html  indicating that I could execute a script. One of the threads I read on the Internet indicated that a possible trigger might be that the createdby field is null - so I created a UI Policy that had two conditions: createdby is empty and the last required field is not empty. I added the single line of scripting code into the 'run if true' script section, and unchecked the 'run if false' script checkbox. It works, but the whole process is rather sloppy since it stalls the screen during the server action, then renders the form again with the focus at the top, plus there are errors in the web console that are cryptic to me. But it works, and the form auto-saves the new record as soon as the required fields are not empty. The user does not have to click a button or choose save from the banner, this automatically performs the save action on the new record, automatically.

I am posting this for my colleagues to use, perhaps someone with more advanced skills ("I am like a baby" - from the movie Avatar) can refine the Ui Policy script so that there are no errors and the form saves and stays at its location instead of returning to the top. Perhaps if I can figure it out I will add the script in a reply, but at this time I don't even know how to post screen shots. At least I can paste the script scrap I used from Alberto's reply:

gsftSubmit(gel('sysverb_update_and_stay'));

Well done Alberto, thank you for contributing to the community!

 

SUMMARY:

in a new UI Policy:

choose advanced view

set the following conditions:

the createdby field is empty AND

the <required field 1> is not empty AND

the <required field 2> is not empty AND

<add a condition for every required field>

then on the script page, uncheck the run if false section

add this line of code to the run if true script section:

gsftSubmit(gel('sysverb_update_and_stay'));

Save the new UI Policy, then fix the errors. A nice touch would be to hide the other UI Action buttons until the new record is saved.

Kind Regards,

Woody

1 ACCEPTED SOLUTION

woodyfairley
Tera Guru

See the solution in the original post, working fine after a few weeks. A minor improvement and suggestion for anyone implementing this behavior is to choose a field in the top most part of the screen as the trigger (if possible) because the auto save will refresh the screen and return your view to the top of the form. I tried implementing a "refocus" portion in the script but I am not yet skilled enough to make it work.

The form's process did not allow me to just move the mandatory fields to the top, so I eliminated all mandatory fields from the original form and constructed a UI Policy that set the mandatory fields after the autosave, enabling the customer to created a draft of the purchase request, which then activated the "mandatory fields" UI Policy and ensured compliance with the process' governance rules. This generated the unique serial number for the customer, who could then inform the approval staff of the intention and then take the time to gather relevant information (if not already collected for the data entry effort).

SUMMARY: construct the form with one or less mandatory fields, then trigger the autosave after completion of the first "interesting" field, then use UI Policy to make it and the other interesting fields mandatory. By the way, this reduces the data entry time-motion burden for users, so they will appreciate it once you explain it and set their expectations.

Kind Regards,

Woody

View solution in original post

2 REPLIES 2

woodyfairley
Tera Guru

See the solution in the original post, working fine after a few weeks. A minor improvement and suggestion for anyone implementing this behavior is to choose a field in the top most part of the screen as the trigger (if possible) because the auto save will refresh the screen and return your view to the top of the form. I tried implementing a "refocus" portion in the script but I am not yet skilled enough to make it work.

The form's process did not allow me to just move the mandatory fields to the top, so I eliminated all mandatory fields from the original form and constructed a UI Policy that set the mandatory fields after the autosave, enabling the customer to created a draft of the purchase request, which then activated the "mandatory fields" UI Policy and ensured compliance with the process' governance rules. This generated the unique serial number for the customer, who could then inform the approval staff of the intention and then take the time to gather relevant information (if not already collected for the data entry effort).

SUMMARY: construct the form with one or less mandatory fields, then trigger the autosave after completion of the first "interesting" field, then use UI Policy to make it and the other interesting fields mandatory. By the way, this reduces the data entry time-motion burden for users, so they will appreciate it once you explain it and set their expectations.

Kind Regards,

Woody

woodyfairley
Tera Guru

For anyone who is implementing this behavior in an application, please note that this will only work in the Global Scope.

Global Scoped applications get access to Global scopes methods like "sysverb_insert_and_stay" or "sysverb_update_and_stay" otherwise the Javascript will error.