Assigning users to groups via workflow trigger

(Kenny Cameron) #1

Matrix Version: 6.34.0

We’re trying to lean into a bit more automation around our site, specifically around the onboarding of users. We’ve got a Training section where they learn the basics, and I’ve set up a workflow where they submit a page, and we approve. There are a few tasks they do to show they can work within Matrix and the workflow approval acts as a sign-off.

So far, I’ve got a trigger set up on After Workflow Approval: removes them from the training group and sets some metadata values on a custom schema applied to their user account (I do this by grabbing asset_created_by_assetid from the page being submitted).

What I would also like to do, is automatically add them/link them to users groups at this stage. The groups won’t be the same for each user, so I’ve attached a related asset picker metadata field to their user account, and we manually drop some groups in.

The idea is that once the approval happens, Matrix can shuffle them into the right place automatically. We could just continue to manually add them to groups after, but if this could work, it would let us set up the accounts and then leave things alone.

What I’ve tried so far

Create Link action:
Looks like you need to explicitly set groups here, and it only allows a single selection, unless there’s something I do with Dynamic parameters and global keywords or something? Couldn’t find a way to get this to work.

Set Future Lineage action:
Same as above, single selection, but no option for using any kind of dynamic parameters.

Assign User To Groups:
I thought I had it with this one, but no joy here either. The fixed users aren’t any use, as it won’t always be the same groups. If “Join by asset name” took IDs instead or as well, I think I’d be set, but I don’t think I can translate the group IDs to name easily inside the trigger (or can I?).
Bearing in mind, the way I get the user ID I want to assign the groups to, comes from the creator of the page being approved — asset_created_by_assetid.
I know on a page I can spit out something like asset_created_by_assetid^as_asset:asset_metadata_matrixUserGroups and get the array of groups, but can you, in a single line, explode out the asset name of those groups without needing SSJS?

It may well be this can’t be done yet, or there might be a better way to handle it. Open to any and all suggestions :slight_smile:

(Iain Simmons) #2

Hi @kennyc,

You almost had it with this part. Try the following as the keyword, but you will also need to select a common parent asset of the Group 1 and Group 2 groups for the Root Node To Join Groups Under field. I can’t remember if it looks more than one level deep, so you may need the groups to be direct children of the root node you select.


I’d suggest trying out keywords like this in a standard page that you can view as some of these users to test with, and then you’ll have a better idea of the format they output.

Obviously the one caveat with that trigger action is that the user groups can’t themselves have commas in their names, and need to be unique.

Hope that helps,

(Kenny Cameron) #3

This looks very promising, thanks for the tips! I’ll give it a try and see how I get on.
Can’t believe I skipped over json_decode, forget about needing that sometimes :sweat_smile:

(Kenny Cameron) #4

@isimmons Unfortunately this hasn’t worked and gave an error when we ran it

I think our group structure will likely play a part in this, as we have a lot of nested groups, and quite a few that are named the same which would definitely cause issues (didn’t realize we had a lot of duplication there) (e.g. Group 1 → Editors, Group 2 → Editors, etc). Not sure how much we can change up the structure to make this work for us, will probably have to explore and alternative — like using the JS API or something.

(Iain Simmons) #5

Oh, maybe try %globals_asset_created_by_assetid^as_asset:asset_metadata_matrixUserGroups^json_decode^as_asset:asset_name^implode:,% ?

It does say global keywords are supported, so maybe it has to be one of those.

And make sure it’s not trying to action on the triggering asset, which I assume is a page or something rather than a user.