Documents ADM
The Documents ADM displays a list of a specific SharePoint document library. If you want to use this object you need to configure the following things.
Create a Copy
Always create a copy of the Ometa.Examples.DocumentADM because upgrades may overwrite this object.
Profile
You need to have an ODBC, REST and SharePoint profile.
The ODBC profile is only for dummy reasons. You can use the default DCS ODBC profile for this. The REST profile is needed for reading, moving, copying, ... the documents from the SharePoint list.
Property | Value |
---|---|
Url | {$SPWeb.Url} |
OAuth Url | https://accounts.accesscontrol.windows.net/{{AAD Id}}/tokens/OAuth/2 |
OAuth Scope | resource;00000003-0000-0ff1-ce00-000000000000/{{domain}.sharepoint.com@{{AAD Id}} |
OAuth Client ID | client_id;{{client Id}}@{{AAD Id}} |
OAuth Client Secret | *************** |
OAuth Grant Type | client_credentials |
The SharePoint profile is needed for deleting documents and updating the properties.
Property | Value |
---|---|
WebSite | {$SPWeb.Url} |
ClientID | {{client Id}} |
ClientSecret | *************** |
Methods
Delete Document
- Update the Interface Script.
- Change the Name property to the name of the SharePoint list.
- If you are working with folders you can specify the StartInFolder property.
Type=ListName
Name=MyList <!-- REQUIRED: Change the name of the SharePoint list -->
Depth=0
Action=Delete
IncludeDocument=false
LookupReturnType=Value
Scope=RecursiveAll
Filter=<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>{$Document ID}</Value></Eq></Where></Query>
StartInFolder=/sites/My Site/Shared Documents/My Folder <!-- OPTIONAL: Only when using folders -->
Dummy Insert Document
This is a dummy method. If you want to add extra metadata (besides default Document Type, Document Tag and Year) you need to add extra input fields.
Get Document
This method fetches the details of a single document.
- Update the Interface Script.
- Change the MyList to your SharePoint list name.
- If you want to include other metadata fields, add new FieldRef elements.
Note
The JSON is formatted for reading purposes. The entire Body must be on a single line!
Method=POST
Path=/_api/web/GetList('{$SPWeb.ServerRelativeUrl}/MyList')/RenderListDataAsStream?$expand=File
Header={"Accept": "application/json;odata=verbose"}
ValueProperty=Row
Body={
"parameters": {
"ViewXml": "<View>
<ViewFields>
<FieldRef Name='FileLeafRef'/>
<FieldRef Name='Name'/>
<FieldRef Name='Title'/>
<FieldRef Name='Document_x0020_Type'/>
<FieldRef Name='Document_x0020_Tag'/>
<FieldRef Name='Year'/>
<FieldRef Name='Editor'/>
<FieldRef Name='Modified'/>
<FieldRef Name='Author'/>
<FieldRef Name='Created'/>
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name='ID' />
<Value Type='Number'>{$Document ID}</Value>
</Eq>
</Where>
</Query>
</View>"
}
}
Get Document Folder
This is an example method on how to use folders. If you are using folders you can copy the contents of this method to the Get Document method.
If you are not using folders, you can safely remove this method.
Get Documents
This method retrieves all the documents from the SharePoint library. This method also accepts a Folder
input field to support folder navigation. If your list does not have folder you can remove the folder input field and , "FolderServerRelativeUrl": "{$SPWeb.ServerRelativeUrl}/MyList{$Folder}"
from the interface script.
- Update the Interface Script.
- Change the MyList to your SharePoint list name.
- If you want to include other metadata fields, add new FieldRef elements.
Note
The JSON is formatted for reading purposes. The entire Body must be on a single line!
If you want to add a custom WHERE clause you can include a QUERY element.
... </ViewFields> <Query> <Where> <Contains> <FieldRef Name='Document_x0020_Type' /> <Value Type='Text'>{$Document Type}</Value> </Contains> </Where> </Query> </View>
If you want to include SORTING you can include an ORDER BY element.
Method=POST
Path=/_api/web/GetList('{$SPWeb.ServerRelativeUrl}/MyList')/RenderListDataAsStream?$expand=File
Header={"Accept": "application/json;odata=verbose"}
ValueProperty=Row
Body={
"parameters": {
"ViewXml": "<View>
<ViewFields>
<FieldRef Name='FileLeafRef'/>
<FieldRef Name='Name'/>
<FieldRef Name='Title'/>
<FieldRef Name='Document_x0020_Type'/>
<FieldRef Name='Document_x0020_Tag'/>
<FieldRef Name='Year'/>
<FieldRef Name='Editor'/>
<FieldRef Name='Modified'/>
<FieldRef Name='Author'/>
<FieldRef Name='Created'/>
</ViewFields>
</View>"
}
}
Get Documents Folder
This is an example method on how to use folders. If you are using folders you can copy the contents of this method to the Get Documents method.
If you are not using folders, you can safely remove this method.
Get Year List
This method is used for generating a year list. Year is a standard metadata column shipped in the Documents ADM and is used as data source in the update and create views.
Update Document Properties
This method updates the properties of a single document.
- Update the Interface Script.
- Change the Name property to the name of the SharePoint list.
- If you are working with folders you can specify the StartInFolder property.
Type=ListName
Name=MyList <!-- REQUIRED: Change the name of the SharePoint list -->
Depth=0
Action=Update
IncludeDocument=false
LookupReturnType=Value
Scope=RecursiveAll
Filter=<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>{$Document ID}</Value></Eq></Where></Query>
StartInFolder=/sites/My Site/Shared Documents/My Folder <!-- OPTIONAL: Only when using folders -->
Add Document
Creates a new document. At the moment there is only support to create new Word documents and PowerPoint presentations.
Copy Document
Copies a specific document. When copying and versioning is enabled, do note that only the last published version will be copied. There is an option to overwrite. You will get an error when the file name already exists and the overwrite option is unchecked.
For security reasons it is best practice to add an extra validation script on the FileRef field:
if ({$this$}.IndexOf("/MyList/", StringComparison.CurrentCultureIgnoreCase) == -1)
throw new Exception("Only files from MyList can be copied");
Move Document
Moves a specific document. When moving and versioning is enabled, all versions are moved as well. There is an option to overwrite the document at the destination if the file name already exists. You will get an error when the file is still checked out, or when the file name already exists and the overwrite option is unchecked.
For security reasons it is best practice to add an extra validation script on the FileRef field:
if ({$this$}.IndexOf("/MyList/", StringComparison.CurrentCultureIgnoreCase) == -1)
throw new Exception("Only files from MyList can be moved");
Publish Document
Publishes a version of the document. The user can specify an optional comment. At the moment there is no support for line breaks in the comment.
For security reasons it is best practice to add an extra validation script on the FileRef field:
if ({$this$}.IndexOf("/MyList/", StringComparison.CurrentCultureIgnoreCase) == -1)
throw new Exception("Only files from MyList can be published");
Views
Get Document
This view is only used for supporting the update view.
Get Documents
This is the main view which should be used in the ADM configuration.
Multi View
Use the multi view in the Views tab if you want to create multiple views. Try to use icons because this is more pleasant for the end users. Use the fa-lg class to make the icon larger. The will be replaced by a whitespace.
<i class="fas fa-folder-open fa-lg"></i>&nbsp;&nbsp;All Documents
Functions
Replace the URL of the Search function. Change Documenten to the name of the SharePoint list.
window.open(`${window.obiz.pageContext.web.serverRelativeUrl}/Documenten`);
Replace the URL of the Quick Edit function. Change Documenten to the name of the SharePoint list. Make sure you have a list view where users can click on quick edit.
window.open(`${window.obiz.pageContext.web.serverRelativeUrl}/Documenten/Forms/Snel%20Bewerken.aspx`);
Replace the URL of the Approval function.
Scripts
You may need to change some parameters in the Configuration Script:
// The name of the documents ADM object.
let docsObject = 'Documents ADM';
// The name of the multi record view.
let docsView = 'Get Documents';
// The name of the single upload view.
let uploadSingleView = 'Upload 1 Document';
// The name of the multi upload view.
let uploadMultipleView = 'Upload Documents';
// The color while hovering with files over the multi record view.
let dropColor = '#9ecbec';
Get Year List
The view for supporting the Year data source field.
Update Document Properties
The view for updating the metadata of a single document.
Upload 1 Document
The view for updating a single document.
- Go to the Select Document view field.
- Go to the Media Target Source settings.
- Change List property from MyList to the name of your SharePoint list.
If you have new metadata field you need to add these as new context fields. Extend the Field Names with the title or internal name of the column in the SharePoint list.
Upload Documents
The view for updating a multiple documents.
- Go to the Select Documents view field.
- Go to the Media Target Source settings.
- Change List property from MyList to the name of your SharePoint list.
If you have new metadata field you need to add these as new context fields. Extend the Field Names with the title or internal name of the column in the SharePoint list.
Add Document
This view is needed to support creation of new documents. At the moment there is only support to create new Word documents and PowerPoint presentations.
Copy Document
This view is needed to copy a document from one location to another. When copying and versioning is enabled, do note that only the last published version will be copied. There is an option to overwrite. You will get an error when the file name already exists and the overwrite option is unchecked.
The destination must be a relative URL to the document, e.g.: /sites/MySite/MyList/MyFolder/MyDocument.docx. To increase UX you need to configure a data source for retrieving the correct destinations.
Move Document
This view is needed to move a document from one location to another. When moving and versioning is enabled, all versions are moved as well. There is an option to overwrite the document at the destination if the file name already exists. You will get an error when the file is still checked out, or when the file name already exists and the overwrite option is unchecked.
The destination must be a relative URL to the document, e.g.: /sites/MySite/MyList/MyFolder/MyDocument.docx. To increase UX you need to configure a data source for retrieving the correct destinations.
Publish Document
This view is needed to publish a document. The user can specify an optional comment. At the moment there is no support for line breaks in the comment.
Folder Navigation
The Documents ADM has support for folder navigation. The user can click on a folder and from that moment breadcrumbs will become visible. When the page is refreshed, the user will still be in the same folder.
Because this works context based by passing the folder as input it will be hard combining this with two documents ADM on the same page. You will need to create multiple input fields for each ADM. By default the scripts do not have support for this.
The support for folder navigation is made by the on load complete event. You will need to update the top variables of this script:
// The name of the list used in the Documents ADM.
const currentList = 'MyList';
// The current object.
const objectName = 'Documents ADM';
// The current view.
const viewName = 'Get Documents';
And everything between /** BEGIN OF Folder Navigation / and /* END OF Folder Navigation */ is also needed to support the folder navigation. When you don't need folder navigation you can remove these things from the script and remove the folder input field.