I have a data field that is a list of items on the user data type. The items are related to another data type called Earnings. The Earnings data type has a field ‘value’, which is a number.
I want to be able to remove from the list field on the user data type the ‘Earnings’ entries based on a dynamic aggregate value.
For example, each entry of ‘Earnings’ field ‘value’ is 30. In the user data type field there are 10 ‘Earnings’ entries, so that would equate to a total value of 300 (30 for each value x 10 entries).
If there is a dynamic value that is 140 for example, I want to be able to remove from the list of ‘Earnings’ the entries whose ‘values’ combine up to the dynamic value of 140, which would result in the list of ‘Earnings’ being reduced by 4 entries (30x4=120) and to also make a change to another field on the ‘Earnings’ data type for the 5th entry whose ‘value’ of 30 would be used for the remaining 20 (difference from the 4 items removed with total value of 120 from the dynamic value of 140), where on that 5th entry another field ‘value remaining’ would be updated to 10 (‘value’ of 30 less the 20 difference = 10 values remaining).
This would need to be done in backend workflows. The dynamic value of 140 in the example will always be unknown in advance of running the functions. The ‘value’ field of 30 in the example might not always be the same for each ‘Earnings’ entry.
I can do this simple enough in a recursive backend workflow, but the goal is to not incur the WU costs of running the recursive backend workflow, so I’m hoping there might be a way to achieve this without a recursive backend workflow.
Any ideas?
This is for a referral credits system. The ‘value’ is the earned credits, which will be used to reduce the costs of a purchase or subscription fee. The ‘Earnings’ data type is tracking the user that earned the credits (ie: ‘value’), status of the ‘Earnings’. Once the ‘Earnings’ status turns to available, it is added to the list field on the User data type.
The goal is to remove from the list field on the User data type the ‘Earnings’ entries whose ‘value’ is applied to a purchase or subscription fee, as well as update an ‘Earnings’ entry whose ‘value’ total was not used so as to track the difference of what was the original value versus what had been used from that specific ‘Earnings’ entry to reduce the purchase or subscription fee. It should be that the purchase price or subscription fee can be reduced to Zero in the event there are enough credits available in the list of ‘Earnings’ on the user data type and any partially used credits can be logged onto the ‘Earnings’ entry whose value of credits was not fully used.