cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Saul85
Helper I
Helper I

Publish dynamic document with File Viewer in a SP Page

Hello!

 

I followed a tutorial on how to make with power automate a dynamic page in Sharepoint.

 

Everything worked until I wanted to add a dynamic document to be displayed in the SP Page using the Link or the File Viewer app.

 

I changed the links and the file name in the json content adding a dynamic value but still not working.

 

Any help on how to do that or any workaround will be appreciated.

 

Thanks in advance.

 

 

13 REPLIES 13
Expiscornovus
Super User II
Super User II

Hi @Saul85,

 

Can you share your json in this thread? It should be possible via some requests via the Send an HTTP request to SharePoint action (post page, checkoutpage, savepageasdraft and publish).

 

Below is an example of a SavePageAsDraft post request with json for adding a FileViewer web part with a dynamic value for a FileLink. Obviously this example is specific to my page layout. But maybe it helps a bit?

 

fileviewer_savepageasdraft.png

 

{"__metadata":{"type":"SP.Publishing.SitePage"},"LayoutWebpartsContent":"[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"Title area\",\"description\":\"Title Region Description\",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{},\"links\":{}},\"dataVersion\":\"1.4\",\"properties\":{\"title\":\"@{variables('Use Case Title')}\",\"imageSourceType\":4,\"layoutType\":\"FullWidthImage\",\"textAlignment\":\"Left\",\"showTopicHeader\":false,\"showPublishDate\":false,\"topicHeader\":\"\",\"authors\":[],\"authorByline\":[\"@{variables('UserName')}\"]},\"reservedHeight\":228}]",
"CanvasContent1":"[{\"controlType\":3,\"id\":\"17f1e690-cdb8-485c-9e39-9c3dfd9da765\",\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"controlIndex\":1,\"layoutIndex\":1},\"webPartId\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"webPartData\":{\"id\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"instanceId\":\"17f1e690-cdb8-485c-9e39-9c3dfd9da765\",\"title\":\"File viewer\",\"description\":\"Display a document or file on your page including Word, Excel, PowerPoint, PDF, 3D models, and more.\",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{\"title\":\"@{variables('FileName')}\"},\"imageSources\":{},\"links\":{\"serverRelativeUrl\":\"@{variables('RelativeUrl')}\",\"wopiurl\":\"@{variables('FileLink')}\"}},\"dataVersion\":\"1.4\",\"properties\":{\"annotation\":\"\",\"authorName\":\"@{variables('UserDisplayName')}\",\"chartitem\":\"\",\"endrange\":\"\",\"excelSettingsType\":\"\",\"file\":\"@{variables('FileLink')}\",\"listId\":\"701e64dd-95ac-4018-8508-ff8619660cd4\",\"modifiedAt\":\"2020-12-22T15:43:22Z\",\"photoUrl\":\"/_layouts/15/userphoto.aspx?size=S&accountname=@{variables('UserName')}\",\"rangeitem\":\"\",\"siteId\":\"@{variables('SiteId')}\",\"startPage\":1,\"startrange\":\"\",\"tableitem\":\"\",\"uniqueId\":\"d2a7575e-d31b-414f-aba7-fb4171c29f8b\",\"wdallowinteractivity\":true,\"wdhidegridlines\":true,\"wdhideheaders\":true,\"webId\":\"@{variables('WebId')}\",\"webAbsoluteUrl\":\"@{variables('SiteUrl')}\"}},\"emphasis\":{},\"reservedHeight\":686,\"reservedWidth\":1180,\"addedFromPersistedData\":true},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]","AuthorByline":["@{variables('UserName')}"],"TopicHeader":"","BannerImageUrl":"/_layouts/15/images/sitepagethumbnail.png","Title":"@{variables('Use Case Title')}"}

 

Hi @Expiscornovus,

 

The Page I'm trying to do is very simple, just a title and the document in the FileViewer.

 

So far this is what I have done with the JSON file and still not showing the dynamic file.

 

 {
    "__metadata":{
       "type":"SP.Publishing.SitePage"
    },
    "LayoutWebpartsContent":"[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"\\n      Title area\\n    \",\"description\":\"\\n      Title area description\\n    \",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{\"imageSource\":\"/_LAYOUTS/IMAGES/SLEEKTEMPLATEIMAGETILE.JPG\"},\"links\":{},\"customMetadata\":{\"imageSource\":{}}},\"dataVersion\":\"1.4\",\"properties\":{\"imageSourceType\":2,\"title\":\"Page Test\",\"textAlignment\":\"Left\",\"showPublishDate\":false,\"authors\":[],\"showTopicHeader\":false,\"authorByline\":[],\"layoutType\":\"NoImage\",\"topicHeader\":\"\",\"translateX\":2.9905178701677606,\"translateY\":21.929824561403507},\"reservedHeight\":131}]",
    "CanvasContent1":"[{\"controlType\":3,\"id\":\"7b84c538-88f9-4b6b-8d13-ffbba77d9cbb\",\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"controlIndex\":1,\"layoutIndex\":1},\"webPartId\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"emphasis\":{},\"reservedHeight\":690,\"reservedWidth\":1180,\"addedFromPersistedData\":true,\"webPartData\":{\"id\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"instanceId\":\"7b84c538-88f9-4b6b-8d13-ffbba77d9cbb\",\"title\":\"File viewer\",\"description\":\"Display a document or file on your page including Word, Excel, PowerPoint, PDF, 3D models, and more.\",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{\"title\":\"@{triggerBody()?['entity']?['fileName']}\"},\"imageSources\":{},\"links\":{\"serverRelativeUrl\":\"@{variables('RelativeUrl')}\",\"wopiurl\":\"@{variables('RelativeUrl')}\"}},\"dataVersion\":\"1.4\",\"properties\":{\"annotation\":\"\",\"authorName\":\"@{triggerOutputs()['headers']['x-ms-user-name-encoded']}\",\"chartitem\":\"\",\"endrange\":\"\",\"excelSettingsType\":\"\",\"file\":\"@{triggerBody()?['entity']?['itemUrl']}\",\"listId\":\"e4fa4651-10ab-410a-ba65-46aecb0b7245\",\"modifiedAt\":\"2020-12-25T13:15:53Z\",\"photoUrl\":\"/_layouts/15/userphoto.aspx?size=S&accountname=@{triggerOutputs()['headers']['x-ms-user-email-encoded']}\",\"rangeitem\":\"\",\"siteId\":\"d53d8feb-989c-474e-a2bd-3bac0371296c\",\"startPage\":1,\"startrange\":\"\",\"tableitem\":\"\",\"uniqueId\":\"f0b9720e-e8d1-4680-984e-c953ae09c363\",\"wdallowinteractivity\":true,\"wdhidegridlines\":true,\"wdhideheaders\":true,\"webId\":\"c65ce2f6-2fb2-46e4-9739-d387e77095f7\",\"webAbsoluteUrl\":\"https://mysite.sharepoint.com/sites/DocumentManagement\"}}},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]",
    "AuthorByline":[
       
    ],
    "TopicHeader":"",
    "BannerImageUrl":"https://mysite.sharepoint.com/_layouts/15/getpreview.ashx?guidSite=d53d8feb989c474ea2bd3bac0371296c&guidWeb=c65ce2f62fb246e49739d387e77095f7&guidFile=f0b9720ee8d14680984ec953ae09c363&ext=pdf",
    "Title":"@{triggerBody()?['entity']?['fileName']}"
 }

 

Thanks in advance.

Expiscornovus
Super User II
Super User II

Hi @Saul85,

 

As far as I am aware the wopiurl and file fields need to be absolute url instead of a relative. Can you try and use an absolute url for these fields and see if it works?

 

Btw, the easiest way to capture the correct json is to repeat the steps of adding a fileviewer web part to your page while you have loaded the developer toolbar on a network tab. 

Hello @Expiscornovus ,

 

I tried with the absolute links as you suggested, but still not working.

 

I guess is the GUID number the one that I need to change.

 

Any idea on how to get the GUID number for a selected file?

 

Thanks.

adr55555
Frequent Visitor

@Expiscornovus , have you been successfully updated the content of a file viewer using the send HTTP request? I have been struggling for days and could use some help.

Saul85
Helper I
Helper I

Hi @adr55555 , I was unable to do it.

 

Sorry

@adr55555, I just retested the flow. I am still able to create a new page, check it out and save it as draft with an embedded file viewer web part.

example_testrun.png

 

To clarify, my flow is not only using that one post savepageasdraft http request action. Like stated earlier, I am also using the two actions below to prepare the page before saving it as a draft.

 

1. Create the page

createapage.png

2. Check out page

 

That id is btw retrieved via a Parse JSON action

 

checkoutpage.png

 

Btw, I will have a look if I can make the body example json of the savepageasdraft a bit easier. Tidy it up.

Expiscornovus
Super User II
Super User II

Hi @Saul85 & @adr55555,

 

I changed the example a bit. In this case I am using a Get file properties actions and retrieving a specific .txt file called foobar.txt. This example also assumes that the page has already been created and is checked out btw.

 

I noticed that other file types require some other settings in the file viewer web part. So, what type do you guys want to embed?

 

22-02: Updated the sample and removed the hardcoded uniqueid. Thanks for sharing that ard55555 🙂

 

1. Add a Get File Properties action.

Retrieve one txt file from a source library. Use the Id of the file to retrieve it.

getfileproperties_onetxtfile.png

 

2. Add a Get file metadata action. Use the identified of the get file properties action.

getfilemetada_etag.png

 

3. Add a Send an HTTP request to SharePoint

I have changed the headers and the body compared to the previous example. It is now using the dynamic values of the Get file properties action and the ETag of the Get file metadata action.

 

Variables I am using within the example below

CanvasContent1ControlId - 17f1e690-cdb8-485c-9e39-9c3dfd9da765

DocumentEmbedWebPartId - b7dd04e1-19ce-4b24-9132-b60a1c2b910d

FileViewerSourceListId - Replace this with your List Id where the preview file is hosted (guid)

PageTitleWebPartId - cbe7b0a9-3504-44dd-a3a3-0e5cacd07788

SiteId - Replace this with your Site Id (guid)

SiteUrl - https://contoso.sharepoint.com/sites/testsite, replace this with your site url

Use Case Title - Replace this with your Page Title

WebId - Replace this with your Web Id (guid)

 

 

{"LayoutWebpartsContent":"[{\"id\":\"@{variables('PageTitleWebPartId')}\",\"instanceId\":\"@{variables('PageTitleWebPartId')}\",\"title\":\"\",\"description\":\"\",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{},\"links\":{}},\"dataVersion\":\"1.4\",\"properties\":{\"title\":\"@{variables('Use Case Title')}\",\"imageSourceType\":4,\"layoutType\":\"FullWidthImage\",\"textAlignment\":\"Left\",\"showTopicHeader\":false,\"showPublishDate\":false,\"topicHeader\":\"\",\"authors\":[],\"authorByline\":[\"@{outputs('Get_file_properties')?['body/Author/Email']}\"]},\"reservedHeight\":228}]",
"CanvasContent1":"[{\"controlType\":3,\"id\":\"@{variables('CanvasContent1ControlId')}\",\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"controlIndex\":1,\"layoutIndex\":1},\"webPartId\":\"@{variables('DocumentEmbedWebPartId')}\",\"webPartData\":{\"id\":\"@{variables('DocumentEmbedWebPartId')}\",\"instanceId\":\"@{variables('CanvasContent1ControlId')}\",\"title\":\"File viewer\",\"description\":\"\",\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{\"title\":\"@{outputs('Get_file_properties')?['body/{Name}']}\"},\"imageSources\":{},\"links\":{\"serverRelativeUrl\":\"@{replace(outputs('Get_file_properties')?['body/{Link}'], variables('RootUrl'), '')}\",\"wopiurl\":\"@{outputs('Get_file_properties')?['body/{Link}']}\"}},\"dataVersion\":\"1.4\",\"properties\":{\"annotation\":\"\",\"authorName\":\"@{outputs('Get_file_properties')?['body/Author/DisplayName']}\",\"chartitem\":\"\",\"endrange\":\"\",\"excelSettingsType\":\"\",\"file\":\"@{outputs('Get_file_properties')?['body/{Link}']}\",\"listId\":\"@{variables('FileViewerSourceListId')}\",\"modifiedAt\":\"@{utcNow()}\",\"photoUrl\":\"@{replace(outputs('Get_file_properties')?['body/Author/Picture'], concat(variables('SiteUrl'),'/_layouts/15/UserPhoto.aspx?Size=L'), '/_layouts/15/UserPhoto.aspx?Size=S')}\",\"rangeitem\":\"\",\"siteId\":\"@{variables('SiteId')}\",\"startPage\":1,\"startrange\":\"\",\"tableitem\":\"\",\"uniqueId\":\"@{replace(replace(split(outputs('Get_file_metadata')?['body/ETag'], ',')?[0], '"{', ''), '}', '')}\",\"wdallowinteractivity\":true,\"wdhidegridlines\":true,\"wdhideheaders\":true,\"webId\":\"@{variables('WebId')}\",\"webAbsoluteUrl\":\"@{variables('SiteUrl')}\"}},\"emphasis\":{},\"reservedHeight\":686,\"reservedWidth\":1180,\"addedFromPersistedData\":true},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]","AuthorByline":["@{outputs('Get_file_properties')?['body/Author/Email']}"],"TopicHeader":"","BannerImageUrl":"/_layouts/15/images/sitepagethumbnail.png","Title":"@{variables('Use Case Title')}"}

 

 

updatehardcodedguiddoc_etag.png

 

Let me know if this example works.

@Saul85, I hope you don't mind that I jumped into your thread. Yours was the only match I found for my situation. 

@Expiscornovus, I am trying to add a video to the File Viewer web part. Here is my situation. End users will upload a video, which I match to a SharePoint list item. The list item contains a field that I am using for the page title and the page URL, so I have several steps prior to saving the page as a draft. All prior steps work as planned. I, too, have more than one Send HTTP Request: 1) create the URI, 2) check out the page, and 3) save the page as draft. 

 

A couple of issues to note: 1) When I grabbed the payload information for the page template, the wopiurl matched the server relative url. 2) I also haven't added nearly as many Dynamic Content Variables as you have.

 

I initially tested to be sure the URL was created correctly and that the page title, topic header, and author byline all filled in correctly. When they did, I then started adding in the video's Dynamic Content Variables: the relative URL, the URL, the file name, and who created the file plus their email address for the created by photo information. At that point, nothing else happens. The video I inserted into the page template remains. 

 

Here is the last step in my flow. I cannot help but think I am close to success. Your assistance is greatly appreciated.

 

flow.png

 

 

adr55555
Frequent Visitor

@Saul85, I found the solution for my issue just before 5 p.m. Thursday and hope that it will work for you, too. 

 

flow.png

 

 

 

I suspect I followed the same tutorial as you in terms of saving a page as a template and updating the title and such. As I am inserting video into a File Viewer web part, I then added these variables to the JSON: the file name, a relative URL for the video, and the full URL for the video. Nada. Although the JSON updated with the file name and URLs, I still saw the video I added to the page template.

Then I saw this little tidbit in one of many Google search results: 

  • Banner Image URL – this is the image which gets rolled up to the News web parts within SharePoint. It will either be the image added to the header section of the page or alternatively, it will be the first image found in the page body. Basically, what you see within the SharePoint web parts is what you’ll get from this field.

 

Oh. OK. I had been ignoring this part of the JSON because I didn't have a banner image, but I did have a thumbnail for the video. That thumbnail is the first image on the page. Back to the JSON I go. Near the end of the JSON, I find this text:

"BannerImageUrl":"https://XXXXXXXXXXX.sharepoint.com/_layouts/15/getpreview.ashx?guidSite=e7325c0e3913462d87670872502e...guidFile=52b4ecd2b9af4678b0e178eacf04d807&ext=mp4".

 

A lightbulb goes on when I see this last bit (guidFile=52b4ecd2b9af4678b0e178eacf04d807&ext=mp4).  I searched for this part (52b4ecd2b9af4678b0e178eacf04d807) on the SharePoint site. The result was the video on the SharePoint page template. Turns out, it's a document ID. When I looked back at the JSON, I found this string repeated in a slightly different form: 

}]","CanvasContent1":"[{\"controlType\":3,\"id\":\"d67a79b9-9ed9-44a3-9df7-91b86cad7501\",\"position\":{\"zoneIndex\":1,\"sectionIndex\":1,\"controlIndex\":1,\"sectionFactor\":12,\"layoutIndex\":1},\"webPartId\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"emphasis\":{},\"reservedHeight\":689,\"reservedWidth\":1180,\"addedFromPersistedData\":true,\"webPartData\":{\"id\":\"b7dd04e1-19ce-4b24-9132-b60a1c2b910d\",\"instanceId\":\"d67a79b9-9ed9-44a3-9df7-91b86cad7501\",\"title\":\"File viewer\",\"description\":\"Display a document or file on your page including Word, Excel, PowerPoint, PDF, 3D models, and more.\",\"audiences\":[],\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{\"title\":\"13\"},\"imageSources\":{},\"links\":{\"serverRelativeUrl\":\"/sites/XXXXXXXXXXXX/Videos/13.mp4\",\"wopiurl\":\"https://XXXXXXXX.sharepoint.com/sites/XXXXXXXXXXXXX/Videos/13.mp4\"}},\"dataVersion\":\"1.4\",\"prop..., AXXXX D\",\"chartitem\":\"\",\"endrange\":\"\",\"excelSettingsType\":\"\",\"file\":\"https://XXXXXXXXX.sharepoint.com/sites/XXXXXXXXXXX/Videos/13.mp4\",\"listId\":\"adfe51c6-3f90-4736-9..."uniqueId\":\"52b4ecd2-b9af-4678-b0e1-78eacf04d807\",\"wdallowinteractivity\":true,\"wdhidegridlines\":true,\"wdhideheaders\":true,\"webId\":\"2bed34b6-8526-490c-8717-

 

Documents have a unique ID, which seems to be referred to as a GUID. However, when I looked back at the outputs for "get file metadata" and "get file properties," I see no mention of a GUID. (Insert gnashing of teeth and swearing.)

 

It has to be in there somewhere. Right? Well, it is, but it's called ETag, which you'll find near the end:

 

output.png

 

 

I used a few composes to clean up the ETag, inserted the variables into the appropriate spots in the JSON, and BOOM!, my SharePoint page updates with the appropriate video. For the uniqueID, I inserted a variable I named Video GUID. The element in the banner image URL string I called Banner Image URL.

 

@Saul85, let me know whether you have any questions. I hope my explanation makes sense. If not, let me know.

Expiscornovus
Super User II
Super User II

@adr55555, great job spotting that error! Great that it works now.

 

I believe I hardcoded that unique ID in my example by accident. But since I was reusing the same text file for testing I didn't spotted that 😁

Thank you, @Expiscornovus! Considering you are a superuser, I take your kudos as a major compliment. Your previous responses definitely filled in a lot of knowledge gaps for me and assured me that I was on the right path. Although frustrating, figuring out this flow was worth the time and effort.

Saul85
Helper I
Helper I

@adr55555 Thanks for your detailed post, I will give a try.

 

Regards.

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (2,146)