You are viewing limited content. For full access, please sign in.

Question

Question

Delay a submit function

asked on September 3, 2018

Hi there,

When a user clicks submit button to submit a form, I need to delay the submission for few seconds and trigger the lookup and check if it meets the condition to submit it, otherwise show the user a message.

just wondering if this is possible at all?

Thanks,

Mary

0 0

Answer

SELECTED ANSWER
replied on September 4, 2018

Personally, I would hide the Submit button entirely, use Custom HTML to add my own Submit button to the form. Attach your verification function to the custom button, if it fails do nothing, if it passes trigger the real submit button with $('.Submit').click();

1 0

Replies

replied on September 4, 2018

If you're looking for the events that determine whether a lookup has completed, they are documented here. You could hide the Submit button until the lookup is finished, and then show it only if the condition is met.

1 0
replied on September 3, 2018

Hi Mary,

This will be possible through the use of Javascript. The below code should hopefully put you on the right track.

$(document).ready(function(){

$('.Submit').click(function(){
alert('This is an alert after the submit button has been pressed'); //provide an alert to the screen
return false; //prevents form from submitting
});

});

In the code, the alert is just a prompt to advise that the submit button was pressed and the "return false" will prevent the form from submitting. What you will need to do is work out a way to trigger your lookup by either retrieving values / doing calculations or inserting values where required and run an " IF else " condition.

 

Regards,

 

Aaron

0 0
replied on September 3, 2018

Hi Aaron,

Thanks for the reply. This part sounds good but how would you delay the whole submission for 5 seconds before showing the user this alert message?

Thanks,

Mary

 

0 0
replied on September 3, 2018

Hi Mary,

It really depends on your requirements. There are a number different ways to achieve what you're after.

Javascript has setTimeout method that will prevent code running for a particular amount of time.

i.e.  setTimeout(function(){ alert("Hello World"); }, 5000);

This should wait for five seconds before providing the alert with Hello World

But if all you need to do is wait until a set number of lookups run after selecting the submit button, there might be a better way to do what you're after.

Regards,

Aaron

0 0
replied on September 3, 2018

Thanks Aaron, I'm looking for those better ways and having no luck. But thanks for your replies anyway. 

0 0
SELECTED ANSWER
replied on September 4, 2018

Personally, I would hide the Submit button entirely, use Custom HTML to add my own Submit button to the form. Attach your verification function to the custom button, if it fails do nothing, if it passes trigger the real submit button with $('.Submit').click();

1 0
replied on September 4, 2018

thank you Jason, that was what I needed! I have another question for you :) 

In my form I'm capping selection of the check boxes for each activities . These activities are stored in the database and I'm retrieving them through lookup rules. when the user selects the check box for the activity and submits the form, a workflow updates the count of that activity on the database. I have an auto refresh on the form to do the lookups every 0.01 second but it actually takes around 2 to 3 seconds for the update to be shown on the form, whether that activity is booked out or not. Now the problem is, if two users choose the same activity at the same time and there was only one spot left, both will be able to submit their forms and go over the maximum number. Is there anyway in the workflows that I can stop two concurrent  submissions or perhaps delay one of them?

0 0
replied on September 5, 2018

You could try using a Simple Synchronization Sequence activity. If you wrap the workflow activities in the Synchronization activity and give them the same identifier, they should wait for the other active ones to complete or the time limit to be reached before they perform the contained activities.

The idea there is that if two come in around the same time, the second process will wait for the first to complete and prevent them from running in parallel. However, it depends on how many processes you're talking about because the Synchronization uses an in-memory "lock" and in my experience it can cause performance issues if you have dozens of processes running close to one another.

0 0
replied on September 5, 2018

would this Simple Synchronization Sequence activity work with the SQL custom activity as well? my only activities that need to be inside Simple Synchronization Sequence activity are inset into SQL database activities? When I tried they didn't work. I had a quick search on the net, and it seems that this activity doesn't work with database changes. Is that right?

0 0
replied on September 5, 2018

As far as I knew they’re meant to work on any activity they contain.

I’ve used them for insert/update activities in the past. The only requirement is a matching synchronization ID.

Where did you see that they don’t work on database changes?

0 0
replied on September 5, 2018

https://answers.laserfiche.com/questions/58798/Simple-Synchronization-Sequence--Clarification-on-Purpose-and-Feature-Request?sort=newest

 

Miruna Babatie / Laserfiche  26324  20 • replied on June 30, 2014

The simple synchronization sequence is designed to allow short, in-memory locks for workflows trying to access the same entry. Normally, if an entry is locked when WF tries to access it, WF waits 5 minutes (by default, though the value is customizable) and retries. Some customers wanted waits under 1 minute because in their situations, the lock was released almost immediately and they wanted their workflows to move on faster.

 

The activity has no impact on Database activities.

 

How about using a SQL sequence to keep track of the current value and generate the next? It would be able to handle multiple requests at the same time and be more efficient since you wouldn't incur the overhead of a second call to SQL and the token calculation.

0 0
replied on September 5, 2018

I gave the instances same static Id of 100. does this ID needs to match with anything? or could be any number?

0 0
replied on September 5, 2018

Interesting. It’s does only need to be a number, but that post sounds like it won’t do what you need. Maybe the reason it worked in my case is that the sequence was shared with non database activities.

0 0
replied on September 5, 2018

Yeah, doesn't seem to be working in my situation unfortunately. I Might try to add another type of activity inside the sequence and see if it works like yours.

Thanks anyway.

0 0
replied on September 6, 2018

I managed to make it to work by combining the SQL activities with some unnecessary activities, like find entry inside the Simple Synchronization Sequence activity. It still didn't work until I've changed the server setting to be on single instance mode and it's all started working as I needed :) 
thanks for your help.

0 0
replied on September 6, 2018

Single Instance Mode would eliminate the need for the Synchronizations. With Single Instance Mode enabled it only allows one active instance of each Workflow and does not them up so they will not start up when the other one finishes unless Forms is set to wait in which case I believe it will keep retrying until it can start an instance.

0 0
replied on September 6, 2018

Yeah I know but interestingly it didn't work on it's own either! I have tried them individually first but didn't work until i used both solutions! very strange.

0 0
replied on September 6, 2018

You know, that actually makes a lot of sense because I've noticed that Single Instance Mode doesn't always detect something as "active" depending on the current task.

It may be that the Synchronization forces it to get detected by whatever enforces the Single Instance rule and the database updates don't get picked up on their own.

0 0
replied on September 6, 2018

true! most probably it's the case.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.