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.
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?
{"__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.
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.
@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.
@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.
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
2. Check out page
That id is btw retrieved via a Parse JSON action
Btw, I will have a look if I can make the body example json of the savepageasdraft a bit easier. Tidy it up.
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.
2. Add a Get file metadata action. Use the identified of the get file properties action.
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')}"}
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.
@Saul85, I found the solution for my issue just before 5 p.m. Thursday and hope that it will work for you, too.
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:
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:
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.
@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.
Hi all, sorry to revive an old thread.
I am trying to update fileviewer webpart with an email that has been received and uploaded to sharepoint as a part of the same flow. I am no web dev, and am slightly confused about how you get those dynamic variables to replace the static content in CanvasContent1. Is that by using get file metadata and file properties action step on the file i wish to place in the fileviewer?
My question is how do I know my files ID or where can I find it also how do I find the JSON data in order to update it? I was trying to recreate these flows but found myself lost here. I went to your YouTube and your videos are very well done but for a novice at SharePoint and power automate like myself I need a little more detail to implement a solution for myself. Any assistance would be appreciated.
User | Count |
---|---|
87 | |
37 | |
25 | |
13 | |
12 |
User | Count |
---|---|
117 | |
55 | |
36 | |
23 | |
21 |