Jump to content

Stop Auto Submit on Details form based on Virtual field value


Recommended Posts

I accidentally posted this in the wrong forum (datapages) so I wanted to repost it here: 

I have some code I'm trying to get to work in the Footer on a Details form to halt AutoSubmit code when a value of 1 is reached in a Virtual field (calculated). The Details datapage is set to go to 'Next Record' on update so the Auto Submit cycles through the records. The problem is that when it gets to the last record it keeps auto submitting and I need it to stop AFTER submitting the last record. 

I found some code on this forum but can't get it to work- that code was older, before virtual fields could be calculated. If anyone knows how to adjust this code to get it to work that'd be really great. 

<script type="text/javascript">
if(document.getElementById("caspioform"))
{
if(document.getElementsByName("cbParamVirtual2")[0].value==1)
  {     
     document.getElementById("caspioform").style.visibility = 'hidden';
     document.write('<font face="arial" color=red size="5">No more Submissions!');     
  }
else
  {
 setTimeout('document.forms["caspioform"].submit()',1000);
       }
}
</script>

 

Link to comment
Share on other sites

Hi @DesiLogi,

I think your code above is not set to go to 'Next Record' in your details page, it will simply submit/update the record that is currently on the first record that is being displayed on your Details Page. It is just like clicking directly on the Update button, and after that, you will be redirected to the Results Page.

Because if you analyze your code, let's say that the value of your virtual field now is 10, so it will go to your else condition (which is basically the code below) which will submit/update the record. After that, it will be redirected to the results page of your Report DataPage without going to the  'Next Record ' in your Details Page

<script type="text/javascript">
if(document.getElementById("caspioform"))
{

 setTimeout('document.forms["caspioform"].submit()',1000);
}
</script>

Kindly elaborate on your workflow, so that we can provide you better solution/suggestions.  What are you trying to achieve with this workflow? and how do you pass and received the values that you are updating in your Details Page?

Kind regards,

TsiBiRu

Link to comment
Share on other sites

Hi TsiBiRu,

The datapage is a Details datapage (not a tabular datapage with this done in the Details view). The 'after Update' of the datapage (last step in the Wizard) is set to go to Next Record. This is so it cycles through related (filtered) records and updates each one. Normally, one would use triggers to do what I need to do but Caspio put custom triggers on a number of my tables, the one this deals with included, and they're locked- so I cannot create triggers on them. Therefore I have to use datapages to manipulate the data. 

Virtual2 is a calculated field that gets the total recordset (all the filtered, related records needed to be updated) and then subtracts the number of records that have actually been updated by this datapage, as they're updated. So Virtual2 counts down to 1 as the Auto Submit updates through the recordset. This works well and gives me the ability to 'know' when all the records in the filtered recordset have actually been updated, and therefore to stop the Auto Submit code from continuing to run. That's what the code above is supposed to do- look at Virtual 2's value, and when it reaches 1 stop going to AutoSubmit. 

NOTE: I don't think I need any 'next record' in the js code itself because the Details datapage is set to go to Next Record on Update. The Auto Submit code does cycle through all records (via Next Record) and updates them correctly.  I just need to stop Auto Submit when Virtual 2 = 1. 

Hope this clarifies the issue and thanks for the hep- 

Link to comment
Share on other sites

I figured out a workaround. Instead of a Virtual field calculating the remaining records in the filtered recordset, and then used in If/Else for stopping auto-submitting when all records have been updated, a filtered View is used instead for the data source. 

This enables the auto-submit to run and when there are no more records to update (because the View filters out updated records) I use the Localization to redirect to a new url when there are no records (351 message). 

So basically, all the records in the recordset get cycled through on the Details datapage (set to go to 'Next Record' after update) and then when there are no further records (because the View datasource is empty) it redirects to a new url. 

A bit of a labyrinthine process but it gets the job done. 

Link to comment
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...