Max date within a SELECT function

So I have a table, Productions, with 3 columns: datetime, ID, production. When this table has a new insert, it kicks off a workflow that kicks off an Action. I want the Action to gather the one new ID field that was part of the row that was inserted into the Productions table. Iโ€™ve attempted multiple variations of a SELECT function using MAX and MAXROW on the datetime column but no luck. Any suggestions? Iโ€™m putting this expression in the โ€œReferenced Rowsโ€ field of the Action. Thanks very much.

Solved Solved
0 7 2,818
1 ACCEPTED SOLUTION

Not quite. The workflow gets the row automaticallyโ€“thatโ€™s just how workflow works. The workflow then invokes a configured action on that row, so the action gets the row specifically because the workflow gives the action the row. From there, other actions invoked by that initial action are only aware of the row theyโ€™re invoked againstโ€“and thatโ€™s entirely up to you to determine.

What it appears youโ€™re trying to do is to respond to a change in Productions table by updating some corresponding entry in the Inventory table. You noted:

Thatโ€™s 100% correct.

Also 100% correct, assuming the value of the IT CLP column of the row from the Productions table is a Ref to a row in the Inventory table.

This is entirely where the breakdown is. Any given action is only aware of the row it was invoked for, but knows nothing about the row it was invoked from. The Update Drive Status action is invoked from a row in Productions for a row in Inventory (the row identified by [IT CLP]), so Update Drive Status is only directly aware of the row in Inventory. You understood this, and were rightly trying to determine what row in Productions triggered the workflow. You simply chose a wrong approach in not understanding what Productions[Production] meant.

This takes us back to thisโ€ฆ

Unfortunately, youโ€™re gong to have to do just thatโ€“thereโ€™s no other option. In my experience, you likely wonโ€™t have to worry about a race condition. It seems that workflow is transactional, so nothing outside the workflow should be updating your data while the workflow is running.

If thatโ€™s not good enough for you (and I can understand why it wouldnโ€™t be), the alternative is to avoid workflow and attempt to perform all the actions from within the app itself with a Form Saved action, and/or by chaining the Inventory update actions to any existing actions that update Productions. The goal would be to organize the actions so they all run within the app directlyโ€“where thereโ€™s no contention with other users, and no chance for a race conditionโ€“rather than in a workflow.

View solution in original post

7 REPLIES 7

Hi @Mike_Davis If you havenโ€™t already, check these out.



Thanks @Lynn. Those are the ones that got me to where I currently am, but no luck so far. As I think about it more, wasnโ€™t sure if there might be a different way to instruct the workflow/action to use the record currently having the insert performed? Maybe thereโ€™s a more accurate way than finding the max record (since another user might perform an insert at the same time).

Steve
Platinum 4
Platinum 4

The workflow will automatically use the row that triggered it.

That action will also automatically use the row that triggered the workflow.

Yep, the action should automatically use that row.

Shouldnโ€™t need any of those.

Ooooh! Please post a screenshot of your actionโ€™s configuration screen.

Thanks @Steve for the time to respond. So Iโ€™ll expand a bit more on the situation. There are actually 2 Actions called in sequence after the Workflow. The first Action that the Workflow kicks off is called โ€œGet Drives To Updateโ€. (I do this because it looks like the Action can only take effect on the table that the Workflow is spawned from, but I want to update records on a different table, Inventory.) In the โ€œGet Drives to Updateโ€ Action I use a Reference Row of โ€œLIST([IT CLP])โ€. Since the Workflow and follow-on Action uses the row that triggered the workflow, Iโ€™m assuming this Action results in a List of a single item and defines the single record in the Inventory table to be updated.

The โ€œGet Drives to Updateโ€ Action then calls the โ€œUpdate Drive Statusโ€ Action. In the Set These Columns property I have: โ€œProductions[Production]โ€. (Screenshot attached). Again, Iโ€™m assuming thereโ€™s only a single item in the dataset so there should only be a single value for Production?

What it does is it updates the correct record in the 2nd table, Inventory, but it concatenates all of the Productions[Production] values into the field versus just the value from the record that triggered the workflow.

So Iโ€™ve been trying to get it to use only the newly inserted record using functions such as MAX or MAXROW, but that doesnโ€™t seem to jive (and isnโ€™t a clean methodology either). Thanks for the help.

Yes, LIST([IT CLP]) will produce a list containing one item: the value of the triggering rowโ€™s IT CLP column.

Productions[Production] is a table-column reference, which produces a list of all values in the named column of the named table. Iโ€™m not sure how you got to your assumption that thereโ€™d be only one value.

Yep.

Typically, the most recently added row will have the highest row number, so you can identify that row with:

MAXROW("Productions", "_ROWNUMBER")

That will give you the Ref value for that row. If you instead only want a value from a column in that row, you can use:

SELECT(
  Productions[wanted-column],
  ([_ROWNUMBER] = MAX(Productions[_ROWNUMBER])
)

(substitute wanted-column appropriately)

See also:

Thanks @Steve. So instead of Productions[Production], is there nomenclature for returning only the value of the Production column thatโ€™s part of the recently inserted recordโ€ฆsince it evidently is passing that record around between workflows and actions? Just donโ€™t want to have to go back to the table to get a max record that may have a newer max record by the time this action executes.

Not quite. The workflow gets the row automaticallyโ€“thatโ€™s just how workflow works. The workflow then invokes a configured action on that row, so the action gets the row specifically because the workflow gives the action the row. From there, other actions invoked by that initial action are only aware of the row theyโ€™re invoked againstโ€“and thatโ€™s entirely up to you to determine.

What it appears youโ€™re trying to do is to respond to a change in Productions table by updating some corresponding entry in the Inventory table. You noted:

Thatโ€™s 100% correct.

Also 100% correct, assuming the value of the IT CLP column of the row from the Productions table is a Ref to a row in the Inventory table.

This is entirely where the breakdown is. Any given action is only aware of the row it was invoked for, but knows nothing about the row it was invoked from. The Update Drive Status action is invoked from a row in Productions for a row in Inventory (the row identified by [IT CLP]), so Update Drive Status is only directly aware of the row in Inventory. You understood this, and were rightly trying to determine what row in Productions triggered the workflow. You simply chose a wrong approach in not understanding what Productions[Production] meant.

This takes us back to thisโ€ฆ

Unfortunately, youโ€™re gong to have to do just thatโ€“thereโ€™s no other option. In my experience, you likely wonโ€™t have to worry about a race condition. It seems that workflow is transactional, so nothing outside the workflow should be updating your data while the workflow is running.

If thatโ€™s not good enough for you (and I can understand why it wouldnโ€™t be), the alternative is to avoid workflow and attempt to perform all the actions from within the app itself with a Form Saved action, and/or by chaining the Inventory update actions to any existing actions that update Productions. The goal would be to organize the actions so they all run within the app directlyโ€“where thereโ€™s no contention with other users, and no chance for a race conditionโ€“rather than in a workflow.

Top Labels in this Space