Creating two separate entries in a collection when using update = create

I wish an action to add a Service Order with multiple tasks based on their status in a stategroup. Is this possible? What would be a creative solution? The code below is invalid syntax, but gives you an idea of what I am trying to accomplish.

'Create Service Order': action { } => update ^ ^ ^ ^ .'Service Orders' = create (
    ....
    'Tasks' = switch ^ .'Repackaging Needed' (
        | 'Yes' => create (
            'Task' = "Example 1"
        ) => switch ^ ^ ^ .'Type' (
            | 'Internal' => ignore
            | 'Sale' as $ => create (
                'Task' = "Example 2"
            )
        ) 
        | 'No' => switch ^ ^ ^ .'Type' (
            | 'Internal' => ignore
            | 'Sale' as $ => create (
                'Task' = "Example 2"
        ) 
    )
)

You can combine multiple update operations on the same collection like this, in a simplified but valid and working example:

'Tasks': collection ['Task'] {
	'Task': text
}
'Create Tasks': action { } => update .'Tasks' = create (
	'Task' = "a"
) => update .'Tasks' = create (
	'Task' = "b"
)

You should be able to use this method and move some of your switch logic to the second update operation to get the desired result.

1 Like