Jump to content

Conditionally change status based on expiration date


Recommended Posts

Hello.

You can implement such a workflow using JavaScript.
First of all, you need to add one HTML block to define the statuses.
Here is the example of the HTML block:

1.png.ad77cfa5635d1e5982dee63da5dbbc7a.png

1. Open Status. You can also insert the link of your registration form in the "href" property.
2. Closed Status.
3. Field to copy the date of the expiration. Use the parameter picker to insert the date value. Use the "Short date" format.

Then you need to add header/footer and insert this snippet of code in the footer:

<script type="text/javascript">

var elemOpen = document.getElementsByClassName('Open');
var elemClose = document.getElementsByClassName('Close');
var elemDate = document.getElementsByClassName('Date');

document.addEventListener('DataPageReady', function () {
 for(var i = 0; i < elemDate.length; i++) {
 var dateArr = elemDate[i].innerHTML.split("/");
 var date = new Date(dateArr[2] + "-" + dateArr[1] + "-" + dateArr[0]).getTime();
 var milSecDay = 86400000;
 var currentDate = Date.now();
 var differDay = (date - currentDate) / milSecDay;

 if(differDay > 4) {
   elemOpen[i].style.display = "";
 } if(differDay < 4) {
   elemClose[i].style.display = "";
 }

}

});
</script>

 

If you want, you can import my application and play around with the datapage to get familiar with this idea.
Find the application attached.

JS_Change_Status_based_on_Date.zip

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