cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

SharePoint List Update column

I'm not entirely sure this is possible, but maybe with a helper column?

 

My SP list has 2 columns:

Current User

Previous User

 

I was looking for a PA flow that, when the Current User is updated, puts the user that has just been overridden from the Current User column, into the Previous User column.

Ie, every time the Current User is update, the Previous User column shows the name that was previously the Current User.

Issue is (I can't work out how to build the flow'), but also, once the Current User is modified, the name that was deleted is no longer there to be 'got' and copied into the Previous User column.

 

Is this possible?

 

Do i need a third column so that the flow goes:

When Current User is modified, copy Helper Column to Previous User, then copy Current User to Helper Column.

So in effect the Helper Column is a duplicate of Current User that doesn't get updated until after the Previous User column is updated??

 

All advice welcomed.

THANK YOU 

1 ACCEPTED SOLUTION

Accepted Solutions

Below is how I would do it using just the two columns. Note that this assumes you are using major versions on your list which is normally the default setting. It also handles not getting into an infinite loop given you are updating the item in the flow which would trigger the flow again and again.

 

Below is the list I'm using for this example. Note that the internal column name for Current User is CurrentUser and Previous User is PreviousUser, and the name of the list is Keep Previous User.

grantjenkins_0-1698574128402.png

 

Below is the full flow. I'll go into each of the actions.

grantjenkins_1-1698574168865.png

 

When an item or file is modified will only trigger when an existing item has been modified - not when the item is initially created which is perfect since we don't have a previous user when we first create the item.

grantjenkins_2-1698574228144.png

 

Send an HTTP request to SharePoint retrieves the previous version of the item that was modified. Note that versions behind the scenes go up in increments of 512 - so version 1 would be 512, version 2 would be 1024, etc. Below is the expression used in the Uri of the HTTP request. I'm only returning the previous Current User as this is all we need.

//Keep Previous User is the name of my list
//CurrentUser is the internal name of my Current User column

_api/web/lists/GetByTitle('Keep Previous User')/items(@{triggerOutputs()?['body/ID']})/Versions(@{sub(mul(int(triggerOutputs()?['body/{VersionNumber}']),512),512)})?$select=CurrentUser

//Headers
Accept
application/json;odata=nometadata

grantjenkins_3-1698574453936.png

 

Condition ensures we only update the item if the Current User has changed so we don't get into an infinite loop. Below are the expressions used for both sides of the condition.

//Current User Email from the trigger
@triggerOutputs()?['body/CurrentUser/Email']

//Current User Email from the previous version
@body('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']

grantjenkins_4-1698574631939.png

 

If the Current User Email is different (has been changed since the last version) then we update the Previous User with the previous versions Current User. ID is from the initial Trigger and Previous User Claims uses the following expression.

@outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']

grantjenkins_5-1698574746827.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

14 REPLIES 14

Solution 1 

Yes, Current user field must duplicated in a temp field (what you called Helper).

So we will have 3 columns in SharePoint : 

  • Current user : X
  • Temp user : X 
  • Previous user : Y

When current user changes : 

  • Current user : Z
  • Temp user : X 
  • Previous user : Y

=> Temp user value goes to Previous user and Current user value goes to Temp user

  • Current user : Z
  • Temp user : Z 
  • Previous user : X

Next will be : 

  • Current user : W
  • Temp user : W
  • Previous user : Z

Solution 2 

Use Rest API to get item version and update the item without the needs of a third column, here is the reference : Get a previous version of a SharePoint list record - OneDrive dev center | Microsoft Learn

----------------------------------------------------------
If I have answered your question, please mark your post as Solved. 🆗✔️
If you like my response, please give it a Thumbs Up. 👍
You can accept more than one post as a solution.

Below is how I would do it using just the two columns. Note that this assumes you are using major versions on your list which is normally the default setting. It also handles not getting into an infinite loop given you are updating the item in the flow which would trigger the flow again and again.

 

Below is the list I'm using for this example. Note that the internal column name for Current User is CurrentUser and Previous User is PreviousUser, and the name of the list is Keep Previous User.

grantjenkins_0-1698574128402.png

 

Below is the full flow. I'll go into each of the actions.

grantjenkins_1-1698574168865.png

 

When an item or file is modified will only trigger when an existing item has been modified - not when the item is initially created which is perfect since we don't have a previous user when we first create the item.

grantjenkins_2-1698574228144.png

 

Send an HTTP request to SharePoint retrieves the previous version of the item that was modified. Note that versions behind the scenes go up in increments of 512 - so version 1 would be 512, version 2 would be 1024, etc. Below is the expression used in the Uri of the HTTP request. I'm only returning the previous Current User as this is all we need.

//Keep Previous User is the name of my list
//CurrentUser is the internal name of my Current User column

_api/web/lists/GetByTitle('Keep Previous User')/items(@{triggerOutputs()?['body/ID']})/Versions(@{sub(mul(int(triggerOutputs()?['body/{VersionNumber}']),512),512)})?$select=CurrentUser

//Headers
Accept
application/json;odata=nometadata

grantjenkins_3-1698574453936.png

 

Condition ensures we only update the item if the Current User has changed so we don't get into an infinite loop. Below are the expressions used for both sides of the condition.

//Current User Email from the trigger
@triggerOutputs()?['body/CurrentUser/Email']

//Current User Email from the previous version
@body('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']

grantjenkins_4-1698574631939.png

 

If the Current User Email is different (has been changed since the last version) then we update the Previous User with the previous versions Current User. ID is from the initial Trigger and Previous User Claims uses the following expression.

@outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']

grantjenkins_5-1698574746827.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Grant, thank you so much. Working this through was a great little challenge and something I really enjoyed. thank you for helping me expand my knowledge. After a bit of fiddling it works exactly as desired! 

 

That said, I do appear to be in some form of reoccurring loop.
Current user moves to Previous User.
Then the flow runs again and Current User copy's to become Previous User too. So essentially both users become the same. 
Actually the flow us running twice every minute on a continual run, presumably just continuing to copy the name, spotting the change and copying it again and again and again.
I've checked everything according to your steps. Any idea what might be causing it? Thanks 

THought I'd start again and rebuild in the hope of cracking the error.

Now however, I'm getting the following error message from the HTTP step in the flow:

Unable to process template language expressions in action 'Send_an_HTTP_request_to_SharePoint' inputs at line '0' and column '0': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.

Fixed this, but back to the issue of it running continually and copying current user to previous user and running repeatedly when a change was made. Humm. Must be to do with the Condition?

It should work the way I set it up - just tested again and working successfully. The flow will always trigger twice since it need to check the previous change. However, the second time it runs, the condition should evaluate to false and the flow would then stop not triggering another one.

 

Below is the second time the flow runs where it doesn't update the item again.

grantjenkins_0-1698933340025.png

 

Can you show what you have for each of your actions, and also confirm that your Condition is set to is not equal to?


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Hiya, Ah, yes that's helpful.
SO, I am getting a TRUE result every time, so it just keeps circling.

I can confirm it is set to IS NOT EQUAL TO and my expressions look the same.
Screenshot:

powersportcp_0-1698936721417.png

I can't work out how to expand the expressions to demonstrate what the code is. Is there a way to do that? Sorry for ignorance.

Can you check to make sure you have Major versions turned on for your list?


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Oh, interesting thought.
Not sure I have 'Major Versions' as an option in List Settings
But this is set to yes. = Create a version each time you edit an item in this list? = YESpowersportcp_0-1698938297000.png

 

If you can expand out each of the actions and take a screenshot that would help. For the expressions, you should be able to click on each one and they copy it and paste in here. Might be worth checking the internal names of your columns to ensure they match up correctly with what you've used in the flow.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Thanks so much for looking at it for me.

 

powersportcp_0-1699017962920.pngpowersportcp_1-1699017976976.png

_api/web/lists/GetByTitle('Sports Equipment Log')/items(@{triggerOutputs()?['body/ID']})/Versions(@{sub(mul(int(triggerOutputs()?['body/{VersionNumber}']),512),512)})?$select=CurrentUser

 

Field=CurrentUser

Field=PreviousUser

Field=Item

Field=Title

 

Code for the Condition is:

 
  "type""If",
  "expression": {
    "not": {
      "equals": [
        "@triggerOutputs()?['body/CurrentUser/Email']",
        "@body('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']"
      ]
    }
  },
  "actions": {
    "Update_item": {
      "type""OpenApiConnection",
      "inputs": {
        "parameters": {
          "dataset""https://sportilyuk.sharepoint.com",
          "table""76b67d2f-903c-49a5-97c6-efc995177de7",
          "id""@triggerOutputs()?['body/ID']",
          "item/Item""@triggerOutputs()?['body/Item']",
          "item/PreviousUser/Claims""@outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['CurrentUser/Email']"
        },
        "host": {
          "apiId""/providers/Microsoft.PowerApps/apis/shared_sharepointonline",
          "connection""shared_sharepointonline",
          "operationId""PatchItem"
        }
      },
      "metadata": {
        "operationMetadataId""977bdfae-a112-4cb3-97a4-473a0fcb2c2f"
      }
    }
  },
  "else": {
    "actions": {}
  },
  "runAfter": {
    "Send_an_HTTP_request_to_SharePoint": [
      "Succeeded"
    ]
  },
  "metadata": {
    "operationMetadataId""2cc9facd-13eb-4b1e-96d9-8f62a70fc70b"
  }
}

I can't see anything wrong with your flow setup.

 

Are you able to go back into one of your flow runs and look at the output you got from the trigger and from the HTTP action for the Current User value - for some reason it's still seeing them as different on the second flow run which is really strange.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Oh I'm glad it doesn't look horribly incorrect!!

 

Looks like it only runs once actually, but then repeats every minute or so.

powersportcp_4-1699024796473.png

 

 

 

Step 1 > When an item or file is modified.
The Output is blank and just says click to download

powersportcp_0-1699023686106.png

 

Step 2: HTTP request:

It picked up 'CurrentUser = Nathan'
 
Condition was TRUE
 
Update item
input
'Previous User Claims'
NATHAN
output
'Current User Claims'
ADAM
'Previous User Claims' 
NATHAN
 
Next minute it runs again
It picked up 'CurrentUser lookup value= Adam'
Condition = true
'Currnt User Claims'
ADAM
'Previous User Claims'
ADAM
 
Repeat.
 
 
HTTP Output is
{
  "CurrentUser": {
    "LookupId": 2283,
    "LookupValue": "NAME",
    "Email": "EMAIL"
  }
}
 
 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (743)