May 17, 2017 / Kannan / 0 Comments
The following code snippet show how to remove duplicate list items in the JSON result of a SharePoint REST call using JavaScript.
Function Definition:
function RemoveDuplicateItems(items, propertyName) {
var result = [];
if (items.length > 0) {
$.each(items, function (index, item) {
if ($.inArray(item[propertyName], result) == -1) {
result.push(item);
}
});
}
return result;
}
Function Usage:
In the below code, assumption is that, the REST call returns data.d.results and the column for which duplicate items need to be removed is Title
var items = data.d.results;
items = RemoveDuplicateItems(items, 'Title');
May 17, 2017 / Kannan / 0 Comments
Following are some of the JSLink URL Tokens I have come across in SharePoint.
- ~site – reference to the current SharePoint site (or “Web”)
- ~sitecollection – reference to the current SharePoint site collection (or “Site”)
- ~layouts – version specific reference to the web application Layouts folder (so it will automatically swap out /_layouts/14 or /_layouts/15 for you)
- ~sitecollectionlayouts – reference to the layouts folder in the current site collection (e.g. /sites/team/_layouts/15)
- ~sitelayouts – reference to the layouts folder in the current site (e.g. /sites/teams/subsite/_layouts/15)
Few Examples:
~sitecollection/_catalogs/masterpage/
~site/siteassets/
~layouts/reputation.js
Source: https://www.martinhatch.com/2013/08/jslink-and-display-templates-part-1.html
May 16, 2017 / Kannan / 0 Comments
The following code shows how to refresh web part without refreshing page in SharePoint.
// Set Ajax refresh context
var eventAjax = {
currentCtx: ctx,
csrAjaxRefresh: true
};
// Initiate Ajax Refresh on the list
AJAXRefreshView(eventAjax, SP.UI.DialogResult.OK);
Source: https://pradiprathod.wordpress.com/2015/05/04/how-to-refresh-list-view-in-sharepoint-2013-using-javascript/
May 15, 2017 / Kannan / 0 Comments
To load multiple JavaScript files in SharePoint JSLink, insert a pipe symbol between multiple JavaScript file links in the JSLink field of webpart’s properties.
JSLink Field Example:
~sitecollection/SiteAssets/jquery.min.js|~site/SiteAssets/my-custom-file.js
A piple symbo is a “|” without quotes
Source: https://egilhansen.com/2013/03/11/jslink-the-simple-way-to-add-and-load-multiple-javascript-files/
May 11, 2017 / Kannan / 0 Comments
Following is the code which can be used to load JavaScript in sequence.
This code for example loads the reputation.js from SharePoint’s layouts folder & jQuery from site assets.
(function () {
ExecuteOrDelayUntilScriptLoaded(function () {
//sp.runtime.js has been loaded
ExecuteOrDelayUntilScriptLoaded(function () {
//sp.js has been loaded
SP.SOD.registerSod('reputation.js', SP.Utilities.Utility.getLayoutsPageUrl('reputation.js'));
SP.SOD.registerSod('jquery-3.2.1', '../SiteAssets/Scripts/jquery-3.2.1.min.js');
SP.SOD.loadMultiple(['reputation.js', 'jquery-3.2.1'], function () {
//reputation.js & jquery-3.2.1.min.js have been loaded.
var context = SP.ClientContext.get_current();
var web = context.get_web();
//Check if jQuery has been loaded
if (typeof jQuery != 'undefined') {
console.log("Jquery is loaded");
}
else {
console.log("Jquery is not loaded!");
}
});
}, "sp.js");
}, "sp.runtime.js");
})();
Source: https://sharepoint.stackexchange.com/questions/92082/uncaught-typeerror-cannot-read-property-get-current-of-undefined
May 5, 2017 / Kannan / 0 Comments
Following are the steps to be implemented in a 2013 workflow to set permissions for a SharePoint list item.
This particular method set the permissions for all users in a group with a particular role permission using REST Calls
1. Build Header Dictionary and set to a variable
Name: Accept
Type: String
Value: application/json;odata=verbose
Name: Content-Type
Type: String
Value: application/json;odata=verbose
1. Set “Group ID URL” to a variable
[%Workflow Context:Current Site URL%]_api/Web/SiteGroups/GetByName('Group Name')?$Select=id
2. Set “Role ID URL” to a variable
[%Workflow Context:Current Site URL%]_api/Web/RoleDefinitions/GetByName('Role Name')?$Select=id
3. Set “Break Role Inheritance URL” to a variable
[%Workflow Context:Current Site URL%]_api/Web/Lists/GetByTitle('Library Name')/items([%Current Item:ID%])/BreakRoleInheritance(copyRoleAssignments=false, clearSubacopes=true)
4. Create Response Variables for “Group ID Response”, “Role ID Response”, “Response Headers” & “Response Code” with data type as Dictionary
5. Make GET REST call using Call Action to “Group ID URL” and assign output to above created variables in step 4
6. Use Get Action ‘d/Id’ from above “Group ID Response” variable and set it to a new variable “GroupID”
7. Make GET REST call using Call Action to “Role ID URL” and assign output to above created variables in step 4
8. Use Get Action ‘d/Id’ from above “Role ID Response” variable and set it to a new variable “RoleID”
9. Make POST REST call using Call Action to “Break Role Inheritance URL” and optionally assign output to above created variables in step 4
10. Set “Set Role URL” to a variable
[%Workflow Context:Current Site URL%]_api/Web/Lists/GetByTitle('Library Name')/items([%Current Item:ID%])/RoleAssignments/AddRoleAssignment(principalId=[%Variable:GroupID%],roleDefId=[%Variable:RoleID%])
Add Role:
AddRoleAssignment(principalId=[%Variable:GroupID%],roleDefId=[%Variable:RoleID%])
Remove Role:
RemoveRoleAssignment(principalId=[%Variable:GroupID%],roleDefId=[%Variable:RoleID%])
11. Make POST REST call using Call Action to “Set Role URL” and optionally assign output to above created variables in step 4
Reference URL: https://msdn.microsoft.com/en-us/library/office/dn531432.aspx
May 5, 2017 / Kannan / 0 Comments
When we fetch document details from the SharePoint, sometimes we may need to get the Author details as well. By default when we do ODATA REST query, we will get only Authorid with a number as a result.
To get Author’s additional details we may need to expand the selected item as show below.
https://server/sites/sitecollection/_api/web/Lists/GetByTitle('Documents')/Items?$select=Author/Title,Author/Name,Author/EMail,Author/MobilePhone,Author/SipAddress,Author/Department,Author/JobTitle,Author/FirstName,Author/LastName,Author/WorkPhone,Author/UserName,Author/Office,Author/ID,Author/Modified,Author/Created,*&$expand=Author
Following list show all the valid Author fields
- Title
- Name
- EMail
- MobilePhone
- SipAddress
- Department
- JobTitle
- FirstName
- LastName
- WorkPhone
- UserName
- Office
- ID
- Modified
- Created
Source: https://social.technet.microsoft.com/wiki/contents/articles/31210.sharepoint-2013-get-user-details-from-person-or-group-field-using-rest-api.aspx
February 10, 2017 / Kannan / 1 Comment
Recently when I tried to add my SharePoint Online (Office 365) site in SharePoint Designer 2013, the login page would repeatedly give the error “the user id or password is incorrect”.
the user id or password is incorrect
I tried both with my domain account and onmicrosoft.com account and was making sure I chose “Work account” when prompted and still it didn’t work.
Then I realised that the multi factor authentication has been enabled recently.
Use “App Password” in SharePoint Designer login page when multi factor authentication is enabled.
So I created an app password and tried logging in and it worked.
The web based login page rendered within the designer’s doesn’t highlight or warn you if you are using multi factored authentication or app specific password
You can learn more about creating the app password here.
January 30, 2017 / Kannan / 0 Comments
One of the consulting request I got was that an user should be able to sync files from a legacy system to O365 SharePoint Library. The issue was that the legacy system was old and all it could do was place a file in a particular folder.
The solution we could offer was the following.
- Configure a Windows mapped drive to point to a SharePoint library
- Configure the legacy system to place file into folder
This worked, but having a mapped drive was received as a security threat by the client’s security team.
But now thanks to the newly launched feature of syncing the SharePoint library files with OneDrive, this is easier.
Best part is, it supports both Windows & Mac.
Read more about it here
Image Source: Office Blog
August 23, 2016 / Kannan / 0 Comments
Following are the features which are not available in SharePoint 2013 Workflow.
- Actions
- Stop Workflow
- Capture a Version of the Document Set
- Send Document Set to Repository
- Set Content Approval Status for the Document Set
- Start Document Set Approval Process
- Declare Record
- Set Content Approval Status
- Undeclare Record
- Add List Item
- Inherit List Item Parent Permissions
- Remove List Item Permissions
- Replace List Item Permissions
- Lookup Manager of a User
- Assign a Form to a Group
- Assign a To-Do Item
- Collect Data from a User
- Start Approval Process
- Start Custom Task Process
- Start Feedback Process
- Copy List Item (SharePoint Designer 2013 supports only the document-copying action.)
- Conditions
- If current item field equals value
- Check list item permission levels
- Check list item permissions
- Steps
- Data sources
- Other features
- Visio integration
- Association Column
- Content Type Association for reusable workflow
- ‘Require Manage List/Web Permission’ feature for list/site workflow
- Globally reusable workflow type
- Workflow visualization option
Source: https://msdn.microsoft.com/en-us/library/jj728659.aspx