O365 SPO: Angular JS based APPS – Business Card development


Seamless Business Card development based on the available metadata of SharePoint User Profile on O365.



Based on the above requirement there are various way to implement the same. Based on my past experience and availability of light weight technologies, I have opted Angular JS based solution, Principal Architecture of the same is as depicted below,


A, B and C: Reperesents deployment of the Azure AD Connect tool (DirSync) on a virtual machine in Azure to synchronize accounts between your on-premises directory and your Azure AD tenant with Office 365

D: Reperesents Azure (the DirSync server) synchronizing on-premises AD DS to Office 365

E: O365 tenant available with you

F: User Profile metadata for a specific user

G: Depicts the view – HTML – It binds the data provided by the H and I

H and I: Model and Controller for Angular JS – consists of the all functions and https REST API call implmentation – This is also responsible to load the data to the collection objects

J: Binding of data

K: Referencing the Model to connect with View and Controller – All files are deployed to Document Library

L: REST API – http GET call to fetch the item from user profile services of O365

O365, SharePoint 2010, 2013, 2016: Updating List item by using JSOM

Applies to :

  • SharePoint Online – O365
  • SharePoint 2010
  • SharePoint 2013
  • SharePoint 2016

Below is the source code to update list item by using JSOM,

var CurrPageUrl;
var PageName;
var webUrl; 
var listName = "PageHitCounts";
var itemId = 1;
var tempPN;
var success = "success";
var failure = "failure";
var siteUrl="My Site URL";
var pagename;
var item;

pagename =  CurrPageUrl.substring(CurrPageUrl.lastIndexOf("/") + 1, CurrPageUrl.lastIndexOf("."));
PageName = pagename;
ExecuteOrDelayUntilScriptLoaded(PageHitOnpageLoad, "sp.js");
 function PageHitOnpageLoad()
var clientContext = new SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(clientContext);
     var oList = clientContext.get_web().get_lists().getByTitle("PageHitCounts");
     var camlQuery = new SP.CamlQuery();
     camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
         '<Value Type=\'Number\'>1</Value></Geq></Where></Query></View>');
     this.collListItem = oList.getItems(camlQuery);
     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 

function onQuerySucceeded(sender, args) 
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();        
     while (listItemEnumerator.moveNext()) 
         var oListItem = listItemEnumerator.get_current();
         listItemInfo += oListItem.get_item(PageName);
         var count = +listItemInfo + +1;
         oListItem.set_item(PageName, count);

function onQueryFailed(sender, args) 
  alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

Hope this help.

Awarded Gold: Microsoft Technet Guru Competition – July 2016

 Awarded Gold in the SharePoint 2010 / 2013 Technical Guru category – July 2016
 SharePoint 2010 / 2013 Technical Guru – July 2016 
0640_NinjaAwardTinyGold Amjad Khan SharePoint SharePoint Online: Create Site Columns, Content Type and Associate with Custom List or Library at site collection level using PowerShell and CSOM John Naguib: “Excellent article”
Ed Price: “I love the diagrams, description at the top, and the download to the code! It would be good to break the long code block up into sections to explain what the code does more. Great formatting with Headers and the TOC!”
0841.NinjaAwardTinySilver Shantha Kumar T Work with host web data using PnP JS library in the SharePoint Hosted Add-In John Naguib: “Incredible to have such topic discussed, excellent”
Ed Price: “Valuable scenario, great descriptions, and good use of images and code! It could benefit from a References section at the end with more resources to dig into.”
7827.NinjaAwardTinyBronze Waqas Sarwar SharePoint 2016 Managing Alternate Access Mapping Using PowerShell (Real World Example) Ed Price: “Good use of a See Also section. This is very clear and easy to read! Includes kudos from Arleta in the comments (“Nice article. Thanks!”). It’s a great scenario that’s well written!”
John Naguib: “Nice article”


O365 and SharePoint: Remove the WebPart from a site by using PowerShell

As we aware the WebpartManager class is helpful in Server side object model. The question popped-up in my mind “Is this possible by using PowerShell scripting?“.

I found answer as “Yes”.

Below is the code snippet to remove webpart from a site by specifying webpartId and site url,

$siteURL = “ht tp://sharePoint/sites/specialsite”; # first constant: site URL
$webpartId = “<guid of your choice for webpart>; # second argument: webpart GUID
$pagepath = “/default.aspx” # change page name or page path here
$pageURL = $siteURL + $pagepath
write-host “Processing site: “, $siteURL
Write-host “Processing page: ” , $pageURL
write-host “Processing webpart ID: ” , $webpartID
$site=new-object Microsoft.SharePoint.SPSite($siteURL)
$webpartmanager=$web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
write-host “Finished.”

O365 and SharePoint: List of WebParts in all sites of Web Application by using PowerShell

As we aware the WebpartManager class is helpful in Server side object model. The question popped-up in my mind “Is this possible by using PowerShell scripting?“.

I found answer as “Yes”.

Below is the code snippet to achieve the same,

$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waCollection = $oContentService.WebApplications;
$log = “.\results.txt” # output file name and path
$pagepath = “/default.aspx” # you can change page name or page path
“Site URL; WebPart Title ; Webpart ID” | out-file $log
$waCollection1 = $waCollection | where-object {$_.IsAdministrationWebApplication -eq $FALSE}
foreach ($wa in $waCollection1)
foreach ($obj in $wa.Sites)
write-host “Processing site: ” , $siteURL
$siteURL = $obj.URL

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

$pageURL = $siteURL + $pagepath
$webpartmanager=$web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
foreach ($webpart in $webpartmanager.WebParts)
$siteURL + “; ” + $webpart.Title + ” ; ” + $webpart.ID | out-file $log -append