Tell us what you are trying to do?
I have a cred form that upon it being submitted and based on a value of a CF I want to update the CF of it's parent.
For example I have:
One to many Box < Customers
Customer CPT that includes a status CF (active, waiting, expired).
Box CPT that includes a status CF (available, rented)
Depending on the value of this CF when the customer form is submitted I want it to update the value of a status of it's parent CF.
e.g. Active = Rented, Waiting = Available, Expired = Available.
I'm sure this is possible with a custom function and would appreciate your kind assistance.
Is there a similar example that we can see?
https://toolset.com/documentation/programmer-reference/cred-api/
https://toolset.com/forums/topic/passing-a-value-from-a-cred-form-to-another-field/
Thank you!
Hello,
Since you are using one-to-many relationship, I assume you are going to:
After user submit the child post form for creating new "Customers" post, check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Available
and so on.
Can you confirm it first?
Hi Luo, thank you for getting back to me.
Yes that's basically it but for editing a customer too because their status maybe set as expired (manually) in which case the box status changes back to available.
The only other approach to this was to remove status CF from box completely and use the customer status to find boxes that are available or rented. The problem with this is that I could never find the number for available. but I could get rented and total boxes. I wondered if calculating difference between item counts could work e.g. total boxes view count - customer boxes active view count but it looks like this is only possible with CF not counts. After reading various support posts I concluded the top solution was actually more workable.
Thank you.
"Check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Available."
Check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Rented
A box-status is 'rented' if any of it's child customer-status is 'active'.
A box-status is 'available' if it has no customer-status as 'active'.
A box can have multiple child customers- status as 'expired' or 'waiting' and the box-status will be 'available'.
It needs custom codes, in order to test and debug the custom PHP codes, I need a live website to test and debug.
How do you setup the post types and custom fields?
Can you reproduce the same problem in below test site?
hidden link
Thank you Luo,
I've recreated the issue on the test site now with a few notes - hidden link
Thanks for the details, I am checking it in the test site, will update here if find anything
Just wondering if there's an update on this.. On the surface it seems Toolset is great for building this type of site but all this coding required seems overkill for something that seems so obvious. I wonder if there's another way around this which avoids so much custom coding? Thanks
I have checked the test site settings,
You are using three custom post types:
- Lockers
- Locker Locations
- Customers
Three pos type relationships:
- One-to-many relationship between "Locker Locations" and "Customers"
- One-to-many relationship between "Locker Locations" and "Lockers"
- One-to-many relationship between "Lockers" and "Customers"
Three post field groups:
- "Lockers" post field group:
Locker Status: Available | Rented
- "Customer" post field group:
Status: Active | Waiting | Expired
- "Locker Locations" post field group
And there isn't any post form in the test site.
It is different settings from this thread, to avoid more misunderstandings, in order to setup the custom codes for you, please confirm this:
You are going to do these:
When user edit/create a "Customer" post, update the parent "Lockers" post field "Locker Status" value by all related "Customer" posts field "status" value.