Editing this so that it’s clearer (taken from my post below):
The process is:
When a listing creator sets up their class, they enter their class schedule using the Full Calendar plugin, e.g. classes on the 25th, 26th, 27th, 28th & 29th November at 8pm.
Once they’ve submitted their listing for review, it becomes Type = Pending. The admin can then ‘approve’ the listing, which marks it as Type = Live. On my search page, I only show listings with Type = Live.
Users can now book the classes from that listing by selecting an available time:
Once the user has booked, we check to see if all available times are gone. If no future booking dates are available, we mark the listing as Type = NoDates.
However, I don’t want to rely on a user to book a class or load the page before running a check to see if dates are available. Some classes may have 0 bookings, e.g. a class creator adds to their schedule: a class on 25th & 26th November at 5pm. They may have 0 bookings and 0 visits to their class page by the 27th November, so no user action will be able to trigger the listing Type of NoDates.
What I require is a background check across all listings to see if listings have upcoming class dates. If a listing has 0 future bookable class dates, then that listing should be marked as Type = NoDates (it’s like pending, but doesn’t require admin re-approval, just requires the user to add more dates on their dashboard for it to become Live again). I can also set up a ‘Send Email’ action to notify the class creator that they need to add more dates.
That means a workflow on page load of the activity won’t work because the listing should be Type = NoDates as soon as no future bookable dates are available.
However, it requires a user to visit the page first, which won’t really work because I’ll be hiding listings with 0 dates from the search.
The main reason I want to do this is so that I can notify the class creators that they need to add more dates to their class schedule, so I need to rely on an automated process rather than someone visiting the page or clicking a button before the ListingStatus changes and the class creator receives an email notification.
I’ll keep trying, a solution can’t be too far off!
When a listing creator sets up their class, they enter their class schedule using the Full Calendar plugin, e.g. classes on the 25th, 26th, 27th, 28th & 29th November at 8pm.
Once they’ve submitted their listing for review, it becomes Type = Pending. The admin can then ‘approve’ the listing, which marks it as Type = Live. On my search page, I only show listings with Type = Live.
Users can now book the classes from that listing by selecting an available time:
Once the user has booked, we check to see if all available times are gone. If no future booking dates are available, we mark the listing as Type = NoDates.
However, I don’t want to rely on a user to book a class or load the page before running a check to see if dates are available. Some classes may have 0 bookings, e.g. a class creator adds to their schedule: a class on 25th & 26th November at 5pm. They may have 0 bookings and 0 visits to their class page by the 27th November, so no user action will be able to trigger the listing Type of NoDates.
What I require is a background check across all listings to see if listings have upcoming class dates. If a listing has 0 future bookable class dates, then that listing should be marked as Type = NoDates (it’s like pending, but doesn’t require admin re-approval, just requires the user to add more dates on their dashboard for it to become Live again). I can also set up a ‘Send Email’ action to notify the class creator that they need to add more dates.
That means a workflow on page load of the activity won’t work because the listing should be Type = NoDates as soon as no future bookable dates are available.
For a background process you need an API workflow. When a listing creator sets up their class, you could schedule an API workflow for the last available date. In this API workflow, you would set the listing to NoDates and also email the listing creator. Search for API workflows in the references and/or forums to learn more.
Yeah it looks like an API workflow is the way to go. The only issue that the user can update their class schedule (add/remove class dates) from their dashboard at any point, so if I schedule the API workflow for a certain date, that date could change (e.g if a class date or time has been removed or added). Can I make changes to the API workflow each time the user updates their class schedule?
Yes, there is an action to cancel a scheduled API workflow. You would then schedule a new one with the new date. Read about cancelling scheduled workflows here.
On a separate page, when I update the class schedule, I want to cancel the original scheduled API workflow, but I’m not sure what the ID is.
Should I create a new data type and store the ID as text? If this is the way to go, I guess I ‘Do a search for’ the Workflow data type’s ID, but wouldn’t be sure which constraints to use.
When you schedule the API, also save its id to the thing (listing?) you scheduled it on, in a field called ‘current_wf_id’ for example. Then when you want to cancel just search for the listing you want to reschedule a workflow for and set the id for the cancellation to that listing’s current_wf_id.
Edit: Re your first question, I think you should be passing a listing to your workflow as a parameter, unless the search you have put in there now will always return the listing you want. If not, here’s what you should do:
Add a parameter of type listing to your API workflow. Let’s call this pListing
Change Thing to change to pListing
On the page, when schedule the workflow, there should now be a parameter pListing toset. Set it to the listing you just created/changed.
When you schedule the API, also save its id to the thing (listing?) you scheduled it on, in a field called ‘current_wf_id’ for example. Then when you want to cancel just search for the listing you want to reschedule a workflow for and set the id for the cancellation to that listing’s current_wf_id.
• Should I create a new text field for the Listing data type (called ‘current_wf_id’ in this case)?
• If I should create a new field, what content goes inside? I can’t see ‘workflow ID’ to save to any existing fields, unless I add it as another action (after creating the Workflow) and then referring to that step, like this:
From your screenshots, your ‘ID’ seems to be the equivalent of my ‘current_wf_id’. Is that correct? Or is the field ID supposed to identify the listing? If so, then don’t use this to store the workflow id. Create a new text field named current_wf_id or something similar and use that instead of ID in your first screenshot.
The rest of looks okay to me.
Now that you are saving the API WF’s ID against the Listing, when you want to reschedule your workflow, just search for the current listing’s current_wf_id in your cancel scheduled API workflow step.
Sorry, ideally I would show you an example but I’m in a bit of a rush. Besides, you seem to be quite close anyway.
Yup, I was using ID as a placeholder rather than creating a new field, I’ve now created ‘Current WF ID’ as a field though, so I’ve set it up to say ‘Current WF ID’ = Result of step 4 (Schedule API workflow).
The only issue now is cancelling the correct Workflow. Inside my ‘Cancel Scheduled API Workflow’, I’m running ‘Search for Listings’s Current WF ID’ as the API ID. This is returning an error though, as it’s currently a ‘List of Texts’ but should return a single text. Should I do ‘:first item’ as I’ll be narrowing down to the exact listing anyway?
It depends on how your page/group is set up, but yes, if you’re using a search you’ll need to constrain it to get to the exact listing you want. Rather than do a search for, can you not simply say Parent group listsing’s Current WF ID?
If you end up using a search then yes, definitely.