Thursday 12 December 2019

Employee Directory Webpart using Modern People Search SharePoint Online

One of our client wanted to show Employee Directory and our first suggestion was to build custom SPFx which will fetch data from Azure AD or Delve and we will add it on page. But the client wanted to use OOTB feature and ask us if we can get something out from people webpart.

And there we invented the Employee Directory using Modern Search. Follow below steps in case you want to implement on your end:

Prerequisite -
1. Install Script Editor webpart. you can download the code from here.

Follow below steps to set up Employee Directory Webpart:

Step 1 - Go to Modern SharePoint Site. Add embed webpart in your page. Type below URL in your

 <iframe id="peopleSearchFrame" src="Your Office 365 Site URL/_layouts/15/search.aspx/people" width="3000" height="6000" scrolling="no"></iframe>  


Step 2 - Add script editor webpart below the embed webpart.
Step 3 - Add below custom css / js to hide unwanted things.
 <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>  
 <script>  
 var myTimerVar = setInterval(designSearch, 20);  
 function designSearch() {  
 $($("iframe")[0]).contents().find('#ms-searchux-serp h2').hide();  
 $($($("iframe")[0]).contents().find(".ms-Button-flexContainer")).hide();  
 $($($("iframe")[0]).contents().find(".SPSearchUX-module__searchFilters___s1xp2")).hide();  
  //CSS for search box and result  
 $($($("iframe")[0]).contents().find("#ms-searchux-serp div")[0]).css("padding","0 0 0 0px");  
 $($($("iframe")[0]).contents().find("#ms-searchux-serp div")[0]).css("border","0");  
 $($($("iframe")[0]).contents().find("#ms-searchux-serp div")[0]).css("padding","8px");  
 $($($("iframe")[0]).contents().find(".ms-searchux").parent('div')).css("padding","0 0 0 0px");  
 $($($("iframe")[0]).contents().find(".ms-searchux").parent('div')).css("border","0");  
 $($($("iframe")[0]).contents().find(".ms-searchux").parent('div')).css("padding","8px");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("border-bottom","2px solid #454545");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("color","#454545");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("font-weight","700");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("font-size","20px");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("padding-bottom","11px");  
 $("[data-automation-id=pageHeader]").find("[role=heading]").css("text-transform","capitalize");  
 $($($("iframe")[0]).contents().find(".SPSearchUX-module__searchFilters___12Rv7")).hide();  
 $($($("iframe")[0]).contents().find("div[class^='backLinkWrapper_']")).hide();  
 $($('div[class="ControlZone"]')[0]).css('padding', '0');  
 $('div[class^="contentBox_"]').css('padding-bottom', '0');  
 }  
 </script>  

Step 4 - Once done, you will see output as follow:



Thursday 7 November 2019

SharePoint Designer Error – Unexpected error on server associating the workflow

I was working on few 2010 reusable workflows in SharePoint Online and I was not able to publish them. I was receiving below error:


I searched for the google and was not able to find anything until I found the blog in reference below. It suggested to check in admin center that if I got any message saying that the service is going to update and it was there.

It stated that the service may be affected till 7th November 2019. In case you are facing same issue wait for the update complete.



Reference -

  • https://social.technet.microsoft.com/Forums/en-US/c4fb5728-bdff-4482-adb6-2a28213fd30e/unexpected-error-on-server-associating-the-workflow-sharepoint-online?forum=onlineservicessharepoint

SPFx general code review points

Recently our client want to code review with Microsoft. We were not sure what can we implement in SPFx. Below were few suggestions after our code review:


1. Do not import * from name space

For this you need to make change in tsconfig.json file. Add compiler option - "allowSyntheticDefaultImports": true. Then you will able to make below change

For example, import * as React from 'react'; should be import React from 'react';

2. Delete unused reference, variables and commented code.

3. Use escape for string property values in tsx

you need to load below name space
import { escape } from '@microsoft/sp-lodash-subset';

Then for sting values use it with escape.
For example, any string property when you use in tsx, instead using -  this.props.scopeType
use it like -  escape(this.props.scopeType);

4. Remove for loops where possible.

For example in below scenario, you can push the whole array instead looping through each item.
for (var j = 0; j < projectTask.length; j++) {
            result.push(projectTask[j]);
          }
Can be done as
result.push(projectTask);

5. Use global varible for hardcoded values

For example, use variable to store site url and replace that with variable name
fetchUrl = "https:/test01.sharepoint.com/sites/ProjectCenter/_api/web/lists/GetByTitle('Projects')/items?$filter=" + filterQuery + "&$top=4999&$select=Title";

could be
var projectCenterURL = "https://test01.sharepoint.com/sites/ProjectCenter";

fetchUrl = projectCenterURL+"/_api/web/lists/GetByTitle('Projects')/items?$filter=" + filterQuery + "&$top=4999&$select=Title";

6. use console log for values instead alert
private _onItemInvoked(item: any): void {
    alert(`Item invoked: ${item.ID}`);
  }

7. Move common methods to common file to improve code re-usability.

8. Use switch case instead of multiple if else statement

9. Enable public CDN and load CSS/ Js files from there.

10. You can make a single fetch api call in common and reuse it instead of writing code again:

fetch(URL, {
        method: 'GET',
        mode: 'cors',
        credentials: "include",     
        headers: new Headers({
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Access-Control-Allow-Origin': '*',
            'Cache-Control': 'no-cache',
            'pragma': 'no-cache',
        }),
    }).then(async(response) => await response.json())
    .then(async(data)=> {
       return data;
    });

SharePoint Designer 2010 Error – Unexpected error on server associating the workflow

If you are experiencing this error try running this command.

For SharePoint 2010
Write-Host “Increasing Workflow parameter UserDefinedWorkflowMaximumComplexity…”
$app = get-spwebapplication http://SharePointWebSiteXXX
$app.UserDefinedWorkflowMaximumComplexity = 20000
$app.Update()
Adding SharePoint 2010 PoweShell cmdlets to your PowerShell ISE
cd ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration’.\SharePoint.ps1


Friday 1 November 2019

Access _spPageContextInfo details in SharePoint Framework

If you are into SharePoint development, then you should be familiar with your best friend _spPageContextInfo which gives you more valuable context-based information. In classic SharePoint Pages, you can access it directly like below:
  1. //This is how you access page context  
  2. _spPageContextInfo.  
  3.   
  4. // retrieve site url  
  5. _spPageContextInfo.webAbsoluteUrl  
You can also access the same now from SharePoint Framework too.
  1. // This is how you can access the page context info  
  2. this.context.pageContext.legacyPageContext;  
  3.   
  4. // Retreive current user display name  
  5. this.context.pageContext.legacyPageContext[‘userDisplayName’]);  
  6.   
  7. // Even site classification  
  8. this.context.pageContext.legacyPageContext[‘siteClassification’]);  
Below is the complete list of object’s properties which sample values,
  1. CorrelationId : "b215479e-f056-5000-11a1-ec000000000010"  
  2. DesignPackageId : "00000000-0000-0000-0000-000000000000"  
  3. PreviewFeaturesEnabled: true  
  4. PublishingFeatureOn : false  
  5. ReycleBinItemCount : -1  
  6. aadInstanceUrl : "https://login.windows.net"  
  7. aadTenantId : "96d8e75d--14a031e2320f"  
  8. aadUserId : "e7d71f70-13e9-0000-0000-86d1269cd536"  
  9. alertsEnabled : true  
  10. allowSilverlightPrompt : "True"  
  11. blockDownloadsExperienceEnabled : false  
  12. canUserCreateMicrosoftForm : true  
  13. canUserCreateVisioDrawing : true  
  14. cdnPrefix : "static.sharepointonline.com/bld"  
  15. crossDomainPhotosEnabled : true  
  16. currentCultureLCID : 1033  
  17. currentCultureName : "en-US"  
  18. currentLanguage : 1033  
  19. currentUICultureName : "en-US"  
  20. departmentId : null  
  21. disableAppViews : false  
  22. disableFlows : false  
  23. env : "prod"  
  24. farmLabel : "US_9_Content"  
  25. fid : 16190  
  26. formDigestTimeoutSeconds : 1800  
  27. groupColor : "#188387"  
  28. groupHasHomepage : true  
  29. groupHasQuickLaunchConversationsLink : false  
  30. groupId : "c771d35a-fee4-4447-9c0a-6c0b199d00fc"  
  31. groupType : "Private"  
  32. guestsEnabled : false  
  33. hasManageWebPermissions : true  
  34. hasPendingWebTemplateExtension : false  
  35. hideSyncButtonOnODB : false  
  36. hubSiteId : null  
  37. idleSessionSignOutEnabled : false  
  38. isAnonymousGuestUser : false  
  39. isAppWeb : false  
  40. isEmailAuthenticationGuestUser : false  
  41. isExternalGuestUser : false  
  42. isHubSite : false  
  43. isMultiGeoTenant : false  
  44. isNoScriptEnabled : true  
  45. isSPO : true  
  46. isSiteAdmin : true  
  47. isTenantDevSite : false  
  48. isWebWelcomePage : false  
  49. layoutsUrl: "_layouts/15"  
  50. listBaseTemplate : 100  
  51. listId : "{7069a902-4347-000-8a03-00fceecfdc70}"  
  52. listPermsMask : {High: 2147483647, Low: 4294705151}  
  53. listTitle : "Property Locations"  
  54. listUrl : "/sites/DemoModernTeamSite/Lists/Property Locations"  
  55. maximumFileSize : 15360  
  56. msGraphEndpointUrl : "graph.microsoft.com"  
  57. navigationInfo : {quickLaunch: Array(14), topNav: Array(2)}  
  58. nid : 107  
  59. openInClient : false  
  60. pageItemId : -1  
  61. pageListId : "{7069a902-0000-4000-8a03-21fceecfdc70}"  
  62. pagePermsMask : null  
  63. pagePersonalizationScope : 1  
  64. preferUserTimeZone : false  
  65. readOnlyState : null  
  66. serverRedirectedUrl : null  
  67. serverRequestPath : "/sites/DemoModernTeamSite/Lists/Property Locations/AllItems.aspx"  
  68. serverTime : "2018-02-04T04:58:48.0656761Z"  
  69. showNGSCDialogForSyncOnODB : false  
  70. howNGSCDialogForSyncOnTS : true  
  71. siteAbsoluteUrl : "https://constoso.sharepoint.com/sites/DemoModernTeamSite"  
  72. siteClassification : ""  
  73. siteClientTag : "0$$16.0.7324.1203"  
  74. siteColor : "#188387"  
  75. siteId : "{1c2e6438-80d2-40cc-9bc5-5aa657c00000}"  
  76. sitePagesEnabled : true  
  77. siteServerRelativeUrl : "/sites/DemoModernTeamSite"  
  78. siteSubscriptionId : "0f6d0000-f22c-47d7-a17f-cd78e6b74a54"  
  79. supportPercentStorePath : true  
  80. supportPoundStorePath : true  
  81. systemUserKey : "i:0h.f|membership|10030000000003d@live.com"  
  82. tenantAppVersion : "3704586950"  
  83. themeCacheToken : "/sites/DemoModernTeamSite:/sites/DemoModernTeamSite/_catalogs/theme/Themed/6FE0689A:9:16.0.7324.1203"  
  84. themedCssFolderUrl : "/sites/DemoModernTeamSite/_catalogs/theme/Themed/6FE0689A"  
  85. themedImageFileNames : {spcommon.png: "spcommon-B35BB0A9.themedpng?ctag=9",  
  86. ellipsis.11x11x32.png: "ellipsis.11x11x32-2F01F47D.themedpng?ctag=9",  
  87. O365BrandSuite.95x30x32.png: "O365BrandSuite.95x30x32-C212E2FD.themedpng?ctag=9",  
  88. socialcommon.png: "socialcommon-6F3394A9.themedpng?ctag=9",  
  89. spnav.png: "spnav-230C537D.themedpng?ctag=9", …}  
  90. userDisplayName : "Rajesh Sitaraman"  
  91. userEmail : "rajesh.sitaraman@contoso.com"  
  92. userFirstDayOfWeek : null  
  93. userId : 3  
  94. userLoginName : "rajesh.sitaraman@contoso.com"  
  95. userTime24 : false  
  96. userTimeZoneData : null  
  97. viewId : "{7edde8c2-5458-42b4-0000-883094b3837e}"  
  98. viewOnlyExperienceEnabled : false  
  99. webAbsoluteUrl : "https://contoso.sharepoint.com/sites/DemoModernTeamSite"  
  100. webDescription : "Demo Modern Team Site"  
  101. webFirstDayOfWeek : 0  
  102. webId : "{8985f800-0000-42f2-899a-abb9f24251e3}"  
  103. webLanguage : 1033  
  104. webLogoUrl : "/sites/DemoModernTeamSite/_api/GroupService/GetGroupImage?  
  105. id='8c1914df-0000-4088-a812-96183d42ae27'&hash=636533140690897999"  
  106. webPermMasks : {High: 2147483647, Low: 4294705151}  
  107. webServerRelativeUrl : "/sites/DemoModernTeamSite"  
  108. webTemplate : "64"  
  109. webTemplateConfiguration : "GROUP#0"  
  110. webTime24 : false  
  111. webTimeZoneData : {Description: "(UTC-08:00) Pacific Time (US and Canada)",  
  112. Bias: 480, Id: 13, DaylightBias: -60, DaylightDate: {…}, …}  
  113. webTitle : "Demo Modern TeamSite"  
  114. webUIVersion : 15  
Reference - https://rjesh.com/spPageContextInfo-spfx/