cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Boppersnr
Helper III
Helper III

How to Initialize a variable for a office365 user field in SharePoint

I am using flow to upload a document to a sharepoint list. One of the metadata to accompany the file contain a Office365 user or group field. 

However when I try to run the flow, all the other metadata fields work and the file uploads but I get an error on the Office365 user field. I wonder am I using the wrong variable type (string).Here is the flow action: 

Boppersnr_0-1642767661030.png

And here is the variable is referenced in the Update file properties action:

Boppersnr_1-1642767706985.png

 

And here is the error:

Boppersnr_2-1642767782013.png

Boppersnr_4-1642767823828.png

Boppersnr_5-1642767852887.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @Boppersnr,

 

It looks like the correct claims data is coming from PowerApps. The formula in PowerApps should be correct.

 

Now, we can focus on the Power Automate flow. Your input is still in a comma separated string format.

 

We want to change that to a claims array. You can use a select action for this. After that you can switch the person field to input an entire array and use the outputs in your person field.

 

Below is an example of that approach.

 

1. Add a Select action directly after your Initialize variable/varTrainingRequirements variable action. Use the expression below in the From field. 

 

 

split(variables('varTrainingRequirements'), ',')

 

 

Map the Claims to the item()

 

create_arraywithselect.png

 

2. The outputs of that action will look something like below.

 

claimsarray.png

 

3. Go to your update file properties action. Switch the input to entire array by click the T button.

 

entiryarray_personfield.png

 

4. Use the Output of Select action.

 

array_users.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

8 REPLIES 8
Expiscornovus
Super User
Super User

Hi @Boppersnr,

 

A claims field for a user normally expects a value something like this:

 

i:0#.f|membership|johndoe@contoso.onmicrosoft.com

 

 

Is see you are trying to input the user displayName. Do you know the UPN or email of the users? If so, you could combine it into a valid claims value by using concat function in an expression.

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


ok, cool.

Where would I input the concat expression. is it somewhere in the flow or in the powerapps screen where I run the flow from?

I changed the powerapps screen field to DisplayName from Claims.

Boppersnr_0-1642940794787.png

Here is my flow run button code: UploadUsertoSharePointList.Run(Last(AttachmentControl.Attachments).Name,varBase64Only,Concat(TrainingRequirements.SelectedItems,DisplayName&", ")

But I still get the error: 

Boppersnr_0-1642970496415.png

 

 

I also changed the Flow Run command to claims (instead of DisplayName), but I get this;

Boppersnr_0-1642970939755.png

Flow run command: UploadUsertoSharePointList.Run(Last(AttachmentControl.Attachments).Name,varBase64Only,Concat(TrainingRequirements.SelectedItems,Claims&", ")

Expiscornovus
Super User
Super User

Hi @Boppersnr,

 

That second attempt with the Claims looks better. However, I see in your PowerApps formula you are concatenating even though it is only a single user? 

 

I think you need to trim the last two characters of the last item of your list of selected items. The PowerApps documentation has an example for that:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-concatenate#trimming...

 

In your case that would be probably something like this:

UploadUsertoSharePointList.Run(Last(AttachmentControl.Attachments).Name,varBase64Only,Left(Concat(TrainingRequirements.SelectedItems,Claims&", "), Len(Concat(TrainingRequirements.SelectedItems,Claims&", ")) -2))

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


@Expiscornovus  yes, that code worked when I made the TrainingRequirements field a single user entry but in this case I want to be able to set it to accept multiple name entries. What code would I need to do to allow more than 1 username

(DisplayName)?

See error when I make the field to allow multiple selections:

Boppersnr_0-1643142095172.pngBoppersnr_1-1643142118015.png

I wonder is it something to do with when I create the variable for it, I have it set as a string, but it wont work if I change to Object or Array either. I get different errors and it wont even import as a flow when I change to that.

Boppersnr_2-1643142216216.png

 

@Expiscornovus  I just deleted a few of the actions in the flow and recreated them and it worked when I input 1 user. but when I add more than 1 I get this error:

Boppersnr_0-1643186458297.png

I guess the code isn't taking into account they are separate entries (users). How can I create flow code to allow multiple entries in a User/Group field?

Expiscornovus
Super User
Super User

Hi @Boppersnr,

 

It looks like the correct claims data is coming from PowerApps. The formula in PowerApps should be correct.

 

Now, we can focus on the Power Automate flow. Your input is still in a comma separated string format.

 

We want to change that to a claims array. You can use a select action for this. After that you can switch the person field to input an entire array and use the outputs in your person field.

 

Below is an example of that approach.

 

1. Add a Select action directly after your Initialize variable/varTrainingRequirements variable action. Use the expression below in the From field. 

 

 

split(variables('varTrainingRequirements'), ',')

 

 

Map the Claims to the item()

 

create_arraywithselect.png

 

2. The outputs of that action will look something like below.

 

claimsarray.png

 

3. Go to your update file properties action. Switch the input to entire array by click the T button.

 

entiryarray_personfield.png

 

4. Use the Output of Select action.

 

array_users.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Boppersnr
Helper III
Helper III

@Expiscornovus  Genius level. That worked. Thanks a mill.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (4,027)