Jump to content

Is It Possible To Filter Records By "previous Month"?


Recommended Posts

Hello everyone!

 

I try to filter records by "previous month", but I cannot find the filter. There are the "Current Month", "Before Now", "Previous X Days" filters. I tried them all one by one and I tried combining of these filters, but the problem is "Previous X Days" is variable. I mean, today the previous month is:

IS Previous 34 days

AND

NOT Current Month

 

But tomorrow it should be 35 days...

 

Any ideas are very much appreciated!

 

Thank you for your time!

Link to comment
Share on other sites

Hello Cameron,


 


You can insert new criteria in your Report DataPage to filter the field by two boundaries. For a Date field you can have two Criteria, FROM and TO so you can search for records that fall within a specific date range. 


 


Hope it helps.


Link to comment
Share on other sites

Hello Cameron,

 

If I understand correctly, you can use a JavaScript code.

 

If you want to filter only by the "previous month" filter:

1) On the "Search Type" step, select "Allow users to select data using a search form";

2) On the "Select Search Fields" step, add your field with date;

3) On the "Configure Search Fields" step,

- select your field with date, select the "Month and Year" in the "Precision" dropdown;

- add Header&Footer element, select "Footer", click the "Source" button and enter the following code:

<SCRIPT LANGUAGE="JavaScript">
if(document.getElementById("caspioform"))
{
  document.getElementById("caspioform").style.display = 'none';
   var nDate = new Date();
   var baseMonth = nDate.getMonth();
   var nPreviousMonth = baseMonth - 1;
   var dPreviousMonth = new Date (nDate.setMonth(nPreviousMonth));
   var searchMonth = dPreviousMonth.getMonth() + 1;
   if (searchMonth<10) {searchMonth  = "0" + searchMonth; }
   var searchYear = dPreviousMonth.getFullYear();
   var searchString = searchMonth + "/" +  searchYear;
   document.getElementById("Value1_1").value=searchString;
  setTimeout('document.forms["caspioform"].submit()',1000);
}
</SCRIPT>

The code enters previous month in the Search field and clicks "Search" button. User does not see the Search page, he or she sees Results page.

 

If you want to filter by other fields,

1) On the "Search Type" step, select "Allow users to select data using a search form";

2) On the "Select Search Fields" step, add fields;

3) On the "Configure Search Fields" step,

- select your field with date, move it up to the first position, select "Hidden" in the "Form element" dropdown, select the "Month and Year" in the "Precision" dropdown;

- add Header&Footer element, select "Footer", click the "Source" button and enter the following code:

<SCRIPT LANGUAGE="JavaScript">
if(document.getElementById("caspioform"))
{
   var nDate = new Date();
   var baseMonth = nDate.getMonth();
   var nPreviousMonth = baseMonth - 1;
   var dPreviousMonth = new Date (nDate.setMonth(nPreviousMonth));
   var searchMonth = dPreviousMonth.getMonth() + 1;
   if (searchMonth<10) {searchMonth  = "0" + searchMonth; }
   var searchYear = dPreviousMonth.getFullYear();
   var searchString = searchMonth + "/" +  searchYear;
   document.getElementById("Value1_1").value=searchString;
}
</SCRIPT>

The code enters previous month as one of search criteria.

 

Does it work for you?

Link to comment
Share on other sites

  • 1 year later...

Hi Jan,

Is it possible to use javascript to filter on the last record entered (potentially via a timestamp), using the same principle of using a search page you have above? I have users submitting multiple records and I need to be able to automatically select the last record submitted to edit, is this possible?

Regards

Jason

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 years later...
On 8/3/2016 at 2:35 PM, scribblemilk said:

Hi Jan,

Is it possible to use javascript to filter on the last record entered (potentially via a timestamp), using the same principle of using a search page you have above? I have users submitting multiple records and I need to be able to automatically select the last record submitted to edit, is this possible?

Regards

Jason

Hi @scribblemilk, you might want to try this workaround that I discover.

 

First, create a Tabular DataPage and choose your data source. Filter the report using your Date field and set the comparison type to 'Before Now'.

1.png.e5a1eab1ae9fefe10efde284079a68ca.png

 

Then, choose the fields for your Results page and paste this script to your Footer. This script will automatically redirect you to details page where you can edit the last submitted record.

<script>

var bulkEditSubmit = document.querySelector('.cbResultSetActionsLinks[data-cb-name=DetailsLink]');
console.log(bulkEditSubmit);

setTimeout( () => { bulkEditSubmit.click(); });

</script>

 

Choose your Date field and sort it in descending order. Set the records per page into 1 only.

2.png.3d066e355c0d4b3336bb1b662ef79d40.png

 

Lastly, enable the Details page and configure the fields you want to be editable. Also, you have the option to disable the navigation to the next or previous records.

3.png.7ce702916c35028078aed57081a6839e.png

 

Here is a sample DataPage I made: https://c0hcv332.caspio.com/dp/3b43900055adaba2de354b22ad43 I hope this helps! :D

Link to comment
Share on other sites

  • 1 month later...
On 7/16/2021 at 3:13 PM, GoodBoy said:

Hi @scribblemilk, you might want to try this workaround that I discover.

 

First, create a Tabular DataPage and choose your data source. Filter the report using your Date field and set the comparison type to 'Before Now'.

1.png.e5a1eab1ae9fefe10efde284079a68ca.png

 

Then, choose the fields for your Results page and paste this script to your Footer. This script will automatically redirect you to details page where you can edit the last submitted record.

<script>

var bulkEditSubmit = document.querySelector('.cbResultSetActionsLinks[data-cb-name=DetailsLink]');
console.log(bulkEditSubmit);

setTimeout( () => { bulkEditSubmit.click(); });

</script>

 

Choose your Date field and sort it in descending order. Set the records per page into 1 only.

2.png.3d066e355c0d4b3336bb1b662ef79d40.png

 

Lastly, enable the Details page and configure the fields you want to be editable. Also, you have the option to disable the navigation to the next or previous records.

3.png.7ce702916c35028078aed57081a6839e.png

 

Here is a sample DataPage I made: https://c0hcv332.caspio.com/dp/3b43900055adaba2de354b22ad43 I hope this helps! :D

Hello! I just want to update this workaround since I have found a way that will show the last submitted record without using any JavaScript.

 

First, delete the existing script I have mentioned in the previous reply. Then, go to the Advanced tab of the Results Page Options window and set the Total Records returned into 1.

image.png.2dbe1d7c9a54903ec3be179d3854e762.png

 

Then, go to the next window and check this checkbox so that it will automatically skip the results page, and show the details page immediately for the last submitted record. Lastly, save the DataPage.

image.png.39c3f4ffef12b12be357221a9a931c9b.png

 

Hope this helps! :D

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...