Saturday, September 28, 2019

Using JSOM to make the Title column clickable on a SP list

I recently had a request to make the Title column of a SharePoint list clickable. You can simply use JSOM to override the template and render the Title column clickable. Don't forget to use "encodeURI" when returning the function in order to prevent issues with & ampersand in the URL.


(function () { 
    var overrideContext = {};
    overrideContext.Templates = {}; 
    overrideContext.Templates.Fields =
    {
        'Title': { 'View': overrideTemplate }
        
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext); 
})();

function overrideTemplate(ctx) {

    var title =    ctx.CurrentItem.Title;
    var name = ctx.CurrentItem["FileLeafRef"];
    var myLink = "https://URL.../" + name;

  
    return "<a id='myAnchor' href=" + encodeURI(myLink) + ">" 
        + title + "</a>";  

   
}

Adding multiple accounts to a SP group using MS Flow and REST API

Here are the steps to include multiple accounts into a SharePoint group using Microsoft Flow and REST API.

1 - Create a SharePoint list with the accounts that you would like to include the SP group.



2 - Create a MS Flow workflow with the following steps:

A) Include a "Get Items" step to retrieve all the accounts from the SP list containing the accounts,



B) Include a "Send an HTTP request to SharePoint". From the Microsoft URL https://msdn.microsoft.com/en-us/library/office/dn531432.aspx we see that the javascript REST call to add a user to a group is the following:

executor.executeAsync({
  url: “<app web url>/_api/SP.AppContextSite(@target)/web    /sitegroups(7)/users    ?@target='<host web url>'”,
  method: “POST”,
  body: “{ ‘__metadata’: { ‘type’: ‘SP.User’ }, ‘LoginName’:’i:0#.w|domain\\user’ }”,
  headers: {
    “accept”: “application/json; odata=verbose”,
    “content-type”: “application/json; odata=verbose”
  },
  success: successHandler,
  error: errorHandler
});




3 - Run the workflow. When these steps are executed, the system will include the users to the SP group.

About Me

My photo
Toronto, Ontario, Canada
MBA, M.Sc. & MCP