Jump to content
AdamH

Need Javascript To Perform A "timestamp Check" On Submission To Create One-Time-Use Form

Recommended Posts

I have a Single Record Update form where once a user has submitted data on Record #123, I want any other users subsequently trying to update Record #123 to be "locked out" from submitting via that form.

 
In other words, I need to be able to disable a form after it's been used once, or when Some_Field = Whatever.
 
You could just disable it with Rules, but if 2 people arrive on the form before either has submitted, then the 2nd User rewrites over the 1st User's data. I need to prevent that from happening.
 
Caspio Support recommends: 
In order to prevent the next users to submit/edit the same record, the "timestamp check" should be done upon form submission. A solution would be to write a JavaScript function to perform the "timestamp check" and then call the function on the form submission event. 
 
Can anyone please assist with this? I'm JavaScript illiterate. Thanks!

Share this post


Link to post
Share on other sites

As a quick update to this, it seems that Support's suggestion is actually impossible with JavaScript. You can't fetch data from a table on submission, only on load. Please correct me if I'm wrong there...

 

Anyhow, I built a workaround for this issue using authentication. (I've spent some time between previous post and this one learning basic JavaScript). I'll post it when I get a minute.

Share this post


Link to post
Share on other sites

Hi AdamH,

 

If I understand correctly, it is possible, if you use two DataPages and redirect.

 

The first DataPage remembers the Timestamp date&time, when a user opens the DataPage. Then a user enters his data to Virtual fields, and when the user clicks "Update", this data and the Timestamp date&time is passed to the second DataPage.

 

Here two Timestamps are compared, and if the Timestamp of the first DataPage is equal to the Timestamp of the second DataPage, the data is edited. Else the message is displayed.

 

I hope I will post the more detailed instructions and the Java Script code soon.

Share this post


Link to post
Share on other sites
Thanks for your response!

 

Let me clarify a bit what I'm looking for so we're on the same page...

 

Anyone coming to my public webform can submit a "Case" via that form.

 

A group of people in my organization are "Supervisors." Each of them will self-assign themselves responsibility for any "Case" (i.e. a single record).

 

This self-assignment is done via a Single Record Update form. They're claiming the responsibility to handle that record/"case."

Supervisor_Name will log the name of the Supervisor who has "claimed" each Record.

 

Using Authentication, we can already know the Supervisor_Name of each Supervisor coming to the Update Form. And we pass the Record_ID in parameters into the Update Form.

 

Supervisor_Name and Record_ID are the only two fields I need in the entire form. So, there is actually nothing for the user to do. Presume he's already logged in previously, then the form already "knows" the two pieces of data it needs.

 

The catch here is this: imagine that the Supervisors are very competitive. As soon as a record is submitted via the initial Submission Form, they all get a notification email about it. Multiple Supervisors will then try to assign themselves that same record at the same time. Think of it as a contest to see which Supervisor can "claim" a record first.

 

Here's my solution, in basic terms: 

 

Firstly, in the Submission Form, assign a value of "not claimed" to Supervisor_Name.

 

Then, in the Update Form, on form load, check if Supervisor_Name is "not claimed" in the table.

If Supervisor_Name is "not claimed," then auto-submit the form via Javascript. (This is presuming the auto-submission works nearly instantaneously).

Else display a message, and hide submit button.

 

As long as there is no significant lag in the auto-submission, this should work, right?

 

Is there a more elegant solution? I think in the way I've got it planned, all a Supervisor has to do is click the link in the notification email, and (presuming he's logged into the app already) the rest will be automatic. He either gets a message like "You've Assigned Yourself Case XYZ" or "Somebody Else Has Already Taken This Case."

Share this post


Link to post
Share on other sites

Hi AdamH,

 

If I understand correctly, you can add one more field, set DateType as Timestamp, in Additional Field Options check "Stamp On Update" and uncheck "Stamp On Insert".

 

Then you can check if this field empty - and if it is empty, then auto-submit the form via Javascript.

 

But it requires one more field, so your solution is probably better.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...