I have a post type with a custom field number and a custom data field. Each user can add his daily number in a new post by cred. I wish to send an email if the value number change (for example more than 5% ) compared to previous (data field) user's post_type.
Hello, it sounds like you need a way to compare the custom field value from a Form submission to another custom field value from a previous submission, to determine whether or not an email notification should be sent. Forms email notifications do not include any built-in triggers exactly like what you have described, so I think the only solution would be to use custom code to create your own conditional notification trigger. We offer two PHP APIs you can use that help you set up your own custom notification conditional triggers:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_event_type
https://toolset.com/documentation/programmer-reference/cred-api/#cred_custom_notification_event_type_condition
Nigel provided examples using these APIs to send notifications conditionally in another ticket here:
https://toolset.com/forums/topic/cred-form-notification-email-conditional-on-generic-field/
You'll have access to the new post ID in those API hook callbacks in the $post_id parameter, so you can get Toolset custom field values from that post using get_post_meta:
$field_slug = 'your-field-slug'; // change this to match your custom field slug from wp-admin
$value = get_post_meta( $post_id, 'wpcf-' . $field_slug, true);
To get the custom field value from a previous post submission, you'll need to query posts somehow and get the post ID of the second most recent submission. For example, a View of posts filtered by post author, where the post author is the same as the author of $post_id, sorted by post date in descending order. Offset the results by 1 to skip the most recent post, and get the next post with a limit of 1 result.
The get_view_query_results API would give you access to the results of such a View, i.e. the User's previous post submission. With that post ID, you can use get_post_meta again to get the custom field value from the previous post, then you could programmatically compare the two custom field values to conditionally trigger or not trigger the notification.
That Views PHP API is documented here:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results
You can see it's a fairly complex scenario that will require developer-level understanding of PHP, Toolset APIs, and WordPress APIs in general. If you're not comfortable writing PHP, you may need to enlist the assistance of an independent contractor to achieve exactly what you're looking for. If you run into problems, I can help troubleshoot any Toolset APIs that don't seem to be working as expected.
My issue is resolved now. Thank you Christian !