Showing posts with label Power Apps. Show all posts
Showing posts with label Power Apps. Show all posts

Sunday, July 9, 2023

Open SharePoint Document Location from Dynamics 365 Button using Power FX

The requirement was to open a SharePoint document location associated to a contact record in a separate tab. I was able to open the associated document location in a separate tab by using the following Power Fx code.

With({
    siteUrl: LookUp('SharePoint Sites', Name = "Default Site").'Absolute URL',
    docLocation: LookUp('Document Locations', Regarding = Self.Selected.Item)
    },
    If(IsBlank(docLocation),
        Notify($"SharePoint document location does not exist for {Self.Selected.Item.'Full Name'}."),
        With({
            url: Replace(siteUrl,1,8,"") //removes https://
            },
            With({
                domain: First(Split(url, "/")).Value //gets domain name
                },
                Launch(siteUrl & "/[YourSharePointListName]/Forms/Today.aspx?RootFolder=" & Replace(url, 1, Len(domain),"") & "/[YourSharePointListName]/" & docLocation.'Relative URL')
            )
        )
    )
)