# App Reference Tracking Part 2 - Enforcing requirements

**URL:** <https://community.tulip.co/t/app-reference-tracking-part-2-enforcing-requirements/11958>\
**Category:** Show and Tell\
**Tags:** apps\
**Created:** [July 10, 2024, 5:48pm UTC](https://community.tulip.co/t/app-reference-tracking-part-2-enforcing-requirements/11958 "2024-07-10T17:48:58Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Richard-SNN](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/richard-snn/32/1166_2.png) [@Richard-SNN](https://community.tulip.co/u/Richard-SNN)\
**Post date:** [July 10, 2024, 5:48pm UTC](https://community.tulip.co/t/app-reference-tracking-part-2-enforcing-requirements/11958/1 "2024-07-10T17:48:58Z")

</div>

In order to keep the post a decent length I won’t be reiterating the content in [Part 1](https://community.tulip.co/t/app-reference-tracking-part-1-simple-object-arrays/11645/6), so if you found yourself here please read it first!

# Demo

# What’s different?

Counting object with requirements is different than Part 1 in many ways, most notably:

1. The Object and Object Array variables now have a new attribute, `Requirements met?`
2. A new table that holds the requirements, and logic to check against the requirements.
3. A new simple array to track if all requirements have been met.

This requires just over double the number of triggers to accomplish:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/2/274c073513a56f0fb96b2dbff5dc308c16aae311.png)

**Note:** It may be technically possible to reduce the number of triggers by one (maybe 2?) but I intentionally did it this way not to obfuscate the logic.

# The Nitty-Gritty Details

## New or Modified Variables

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/3/374065cd3e5ad7b2aef8254c862d660195741de6.png)

This variable is used to “collect” the Boolean `Yes | No` values from the `Record Object Array`.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/b/be5d959964e759e0b8075c5373e7ed63b3bc7a05.png)

This variable is used to know the total quantity of a particular animal including both the count of ones already added and the count of the new request so we can know if the new request would exceed the required quantity or not.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/8/8843e14a9b796f78c521c3111d5602e9b54c97b4.png)

This variable counts the total number of items that have been added to the `Record Object Array`.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/0/0d9fbec7f8486a7d3908e25891c66da0d8bd18cb.png)

As mentioned previously, this object variable has gained a new attribute, `Requirements met?`.

## Putting it all together

Now let’s break down each trigger:

### Load record if available

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/b/b6fb18f14c7b55e7e4d83a38c85ec4400edf6309.png)

Here we check to see if the requested item is in the table, and if so, load the record. I do have an `Else If` (not pictured) to just show an error message and transition back to the same step if the item isn’t found.

### Check requested quantity

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/7/7590d6270c459bf53252e64aa690cf287718fd7d.png)

This trigger is just a high level check to make sure the requested quantity is not more than the required quantity.

### Check for Existing Items

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/a8d99804c3b2e95357c4b0387c492b26429d6ae5.png)

I cheated the screenshot a bit to get it in one but once again, we can only check to see if an array is empty so the first `If` clause is a `no-op` if that’s the case. Otherwise we pull all the items from the existing `Record Object Array` and store them in a simple array to be used in a subsequent trigger.

### Check if item exists & calculate total

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/1/1c37184d123a4e060bb82fef037953e89c2c9411.png)

In the first half of this trigger we check to see if the item being requested has already been added, if so we pull the object out of the array so it can be modified and calculate the new quantity for that item.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/6/631b234cd2f45fe77e7977186e1256a82a8a5140.png)

Otherwise we treat it as a new item and prep a new object to be pushed onto the object array.

**Note:** The last part increments the `Count of Items` variable which is used to know if all of the required items have been added. If you’re on Release 277 or higher you can get the length of the array instead.

### Check requirements and merge

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/5/5bcd76a504d213a499962247d8469a00f5afe9d6.png)

Here we check to see if the requested item has already met the requirements, and if so we show an error, push the `Working Object` back on to the `Record Object Array` and exit the trigger sequence by going back to the step.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/4/44c8aaf052dad25b40ee4e8307bbb15ae2127018.png)

Now we check to see if if the total quantity exceeds the required quantity and if so do the same as the previous conditional.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/7/7b392cfb45b4f2ac478de5f8f35bfc9bc70935a5.png)

If the current quantity meets requirements then we change `Requirements met?` to `Yes` and push the object onto the array.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/2/22f5821b1ada9a8d686af721038a419996209e82.png)

Lastly, if none of the previous are true, then it means we can add the request to the object array but it has not met the requirements.

### Check all requirements met

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/5/58cb8fd4c627a478d2643ec3ccb044a13c439602.png)

Almost there I promise! This trigger simply copies the `Requirements met?` attribute of each object into a simple array so we can perform the final check in the next trigger.

### All requirements met?

Remember that variable `Count of Items` I mentioned earlier? Here’s when we use it. It’s possible and even likely that the `All Requirements Array` may only contain `Yes` and yet we’re still missing item requirements.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/a1113ecea2d565e5a73639456b8b3e5c6f830076.png)

This first check it to see if either of the requirements fail.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/b/ba3f2647e0046f467806152979a2f2814c680e26.png)

If neither of the previous checks fail then total item count and item quantities must match the requirements.

---

_[View the full topic](https://community.tulip.co/t/app-reference-tracking-part-2-enforcing-requirements/11958)._
