Views:

Scenario Overview


This example follows on from xRM Formula #111 and demonstrates how to solve the custom SharePoint folder structure requirement using a Decision Table instead of the Classic style formula.

The business requirement from the customer was that they did not want to use the standard Sharepoint folder structure. Instead, they are grouping their documents by geographical location.

Continent -> Country -> City

This is determined by 3 OptionSets on the Account record.

xCache Records

We will be using the same 4 xCache Records from the earlier formula:

  • SharePoint_Site: Contains the URL to the SharePoint Site we are using
  • SharePoint_SiteCollection: Contains the URL to the Collection we are working with on SharePoint
  • SharePoint_Username: Username to access SharePoint 
  • SharePoint_Password: Access Password for SharePoint

N52 Formula Manager Solution - Decision Table

The Formula Manager solution works like this,

  • We create a formula of type 'Save - To Current Record' on the Document Location entity
  • The formula will fire on Create of the Document Location only.
  • It will create the necessary folders if they don't already exist
  • It will delete the folder created on SharePoint automatically
  • Then it updates the relative URL field on the Document Location to the new folder path


Calculations

This Decision Table uses 4 calculations. 3 will retrieve values from the entity in the Regarding field. The fourth will return a True or False value confirming if each of the fields contains data.

Continent

[sharepointdocumentlocation.regardingobjectid.new_continent_fmt.?]

Country

[sharepointdocumentlocation.regardingobjectid.new_country_fmt.?]

City

[sharepointdocumentlocation.regardingobjectid.new_city_fmt.?]

SharePoint Fields Filled Out

ContainsData(GetVar('Continent'),GetVar('County'),GetVar('City'))

Actions

We use 2 actions in this Decision Table, the first one will create the folders using the value that is currently in the FolderPath Decision Table Calculation. The second is used to delete the folder automatically created by Microsoft out on SharePoint which automatically creates even before the creation of the Document Location entity in Dynamics 365.



CreateFolder

SharePointCreateFolder(
  xCacheGetGlobal('SharePoint_Site'), 
  xCacheGetGlobal('SharePoint_Username'), 
  xCacheGetGlobal('SharePoint_Password'),
  true,
  xCacheGetGlobal('SharePoint_SiteCollection') + GetVar('FolderPath'),
  true
)




DeleteFolder

SharePointDeleteFolder(
  xCacheGetGlobal('SharePoint_Site'), 
  xCacheGetGlobal('SharePoint_Username'), 
  xCacheGetGlobal('SharePoint_Password'),
  true,
  xCacheGetGlobal('SharePoint_SiteCollection') + [sharepointdocumentlocation.relativeurl]
)

The Document Location on the Account



SharePoint Folder

Wizard - xCacheGetGlobal

Please see below the wizard you can use to create the xCacheGetGlobal() function call used in this formula. 

Note you will need to create the xCache beforehand.