Skip to main content

Notifications

Community site session details

Community site session details

Session Id : zFPyIkNeYestikmkzHzFmy
Power Automate - Building Flows
Answered

Opening a Sharepoint Document in Read-Only Mode

Like (0) ShareShare
ReportReport
Posted on 1 Dec 2020 13:39:49 by 195

Hi, 

I have a PowerApp whereby a case is created and a document is saved to the Sharepoint Document Library and referenced by the case. Whilst the document goes through various stages of approval, it can be viewed and edited by clicking a link to it using the command Launch(First(colSelectedDocuments).'Link to item'). This all works fine!

 

However, what I would like to be able to do, is when the document has been fully approved, is there a way to change the link so that the document only opens in Read-Only mode?

 

I've since tried building this in Power Automate, but I get stuck on the first HTTP request;

https://sergeluca.wordpress.com/2018/05/03/assign-unique-permissions-to-a-document-with-the-new-send...

 

The error I get is:

The expression "lists/getByTitle(‘Documents’)/items(1)/breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)" is not valid.
clientRequestId: cb961482-17a5-4d40-ae78-893386123126
serviceRequestId: 820a939f-c0ee-2000-70ec-a673bfc63c7a

 

(I've tried changing the Items parameter to the ID of a document in the list...still no luck.  /items(1)/

Many thanks

Paul

  • Nova13055 Profile Picture
    20 on 06 May 2021 at 09:34:00
    Re: Opening a Sharepoint Document in Read-Only Mode

    Just change the "action=default" to "action=view" in the link property of document.

    Open Documents Read-Only in Modern SharePoint | IBS Microsoft 365 and SharePoint Blog

  • Pstork1 Profile Picture
    66,089 Most Valuable Professional on 08 Dec 2020 at 15:14:16
    Re: Opening a Sharepoint Document in Read-Only Mode

    See my explanation above.  This is what I would expect.

  • Pstork1 Profile Picture
    66,089 Most Valuable Professional on 08 Dec 2020 at 15:13:43
    Re: Opening a Sharepoint Document in Read-Only Mode

    Yes, Remove ByLoginName is the right syntax.  But you will get a Bad Gateway error if the Group doesn't have permissions.  If this is the first time through after breaking security inheritance than the group won't have permissions and you will get an error.  But it should work if the group has read permissions because this is the second time adjusting permissions.

  • PJBruen Profile Picture
    195 on 08 Dec 2020 at 11:32:59
    Re: Opening a Sharepoint Document in Read-Only Mode

    @Pstork1 

    So, I tried the following:

    If I create a new Sharepoint File and run the READ-ONLY process, then the flow errors with the details above.

    If I create a new Sharepoint File and run the EDIT process and then the READ-ONLY process, it seems to work fine.

     

    Would this be what you'd expect?

    I don't fully understand this, but as long as it works I'm happy I think!

     

      

  • PJBruen Profile Picture
    195 on 08 Dec 2020 at 10:39:45
    Re: Opening a Sharepoint Document in Read-Only Mode

    Hi @Pstork1 

    Sorry - I still haven't got this quite right.

    PJBruen_0-1607423670973.png

    This is the URI being entered here:

     _api/web/lists/getByTitle('Documents')/items(11441)/RoleAssignments/groups/RemoveByLoginName('Stress Testing Datastore Members')

     

    The error coming back as Bad Gateway (although the flow was still running, but cancelled after a few mins):

    PJBruen_1-1607423783508.png

     

    Is "RemoveByLoginName" correct as this is the Group name as opposed to an individual?

     

    Sorry again to keep hassling you.

     

    Regards

    Paul 

     

  • Pstork1 Profile Picture
    66,089 Most Valuable Professional on 07 Dec 2020 at 15:07:13
    Re: Opening a Sharepoint Document in Read-Only Mode

    The change in red is the correct change.  Everything should work if its setup that way.

  • PJBruen Profile Picture
    195 on 07 Dec 2020 at 14:27:37
    Re: Opening a Sharepoint Document in Read-Only Mode

    Hi @Pstork1 

    So, these are the 4 HTTP Send Requests I'm making. I've made one change in red, but wasn't sure what to change in the other (sorry, so confused by this). Can you confirm please?

    _api/lists/getByTitle('varLISTNAME')/items(varID)/breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)

    _api/web/SiteGroups/getbyname('varPERMISSIONGROUP')

    _api/web/lists/getByTitle('varLISTNAME')/items(varID)/RoleAssignments/groups/RemoveByLoginName('varPERMISSIONGROUP')

    _api/lists/getByTitle('varLISTNAME')/items(varID)/roleassignments/addroleassignment(principalid='varGroupID',roledefid=1073741826)

  • Pstork1 Profile Picture
    66,089 Most Valuable Professional on 07 Dec 2020 at 13:56:40
    Re: Opening a Sharepoint Document in Read-Only Mode

    OK, I see the error.  In the first of the two statements that removes the permissions you are doing it at the list level not the item level.  Everything up through role assignments should be the same on both commands.  in your example you are trying to remove permissions from the list and set them on the item.  Both of those need to be at the item level.

  • PJBruen Profile Picture
    195 on 07 Dec 2020 at 13:51:23
    Re: Opening a Sharepoint Document in Read-Only Mode

    Hi @Pstork1 

    Is that not the purpose of this step though, which is running in my flow.....or am I missing something else?

    PJBruen_0-1607348919942.png

    Sorry to keep hassling you. This is the first time I've ever looked at this stuff, and it's a bit foreign to me, so your help is much appreciated.

     

    Regards,

    Paul

  • Pstork1 Profile Picture
    66,089 Most Valuable Professional on 07 Dec 2020 at 13:37:58
    Re: Opening a Sharepoint Document in Read-Only Mode

    The error suggests that you are trying to do those steps without breaking security inheritance first.  Any time you are going to set specific permissions you have to be sure that inheritance is turned off.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,089 Most Valuable Professional

Leaderboard
Loading started
Loading complete