We use two lists to keep track of some computers we refurbish. There is one list for Supply and one for Sales.
In the Sales list there is a filtered lookup field that allows you to choose from items (choose by the list item ID) in the Supply list whose "Sold" field is not set to Yes.
So, since the user has added an item from the Supply, I have created a workflow to mark Supply's "Sold" field to true.
This works like a charm.
My problem is this - what if a user decides he chose the wrong Supply item and removes the old value and adds a new one? Or what if he removes the value? That means I need to have the workflow mark the deleted/changed item as unsold in the Supply list.
To complicate matters, the selector in Sales allows for multiple selections of the Supply IDs. This is because one sale might involve more than one item, so the user selects all the available items he needs.
A bit of info:
Premise: In Sales, there is a multi-select lookup that allows the user to choose from items in Supply (selecting by the list ID field) if the item's "Sold" field is not marked to "yes". The user can only choose from a list of items that are not sold, so there is no risk of entering an already-sold item.
Goal: When a user uses the Sales list to select unsold items from Supply, Sharepoint should go and mark the Supply item as sold.
Problem: If a user changes the Supply ID in Sales, this needs to be reflected in Supply. In other words, if the item is removed from the Sales list, it needs to get "unsold" in Supply. And since the user can choose more than one item, this needs to happen for each item in the sale.
So, here is a list of what I think needs to be accomplished somehow:
- Before a user adds/changes the StockIDs in the Sales list, fetch the current value into a variable called "SupplyArchiveID"
- The user makes their edits normally, and selects Supply items
- Sharepoint checks to see if the before and after states are different.
- Sharepoint marks both the current items sold.
- Sharepoint marks as unsold any items that exist in the originalStockID but don't exist in the updated list.
Now, how can I accomodate that in the workflow?
- I can fetch the old values into a field in the list whenever an edit is made. Now, when the user saves the list item, I have both the new value and the old value.
- How do I compare the two arrays?
I've tried this:
- First I created a column called SupplyArchiveID to be used by the workflow.
- If there is an item in SupplyArchiveID that is in StockID, then in the Supply List, mark the item a sold.
- If there is an item in SupplyArchiveID that is NOT in StockID, then in Supply List, mark the item as unsold.
- Finally, equalize the two values (StockID and SupplyArchiveID) for when we restart the process.
But this doesn't work right. I am not sure that
contains is checking against every value. I am thinking it doesn't work this way.