Saturday, 27 April 2019

SharePoint Online Allow custom scripts - Part 2

We have looked at why Microsoft disabled custom scripts in SharePoint Online and where it affects. If you have not gone through that, please click here to read it.
In this post, we are going to review how to enable custom scripting on tenant level and what will be its impact.

Enable Scripting at the Site Collection Level 

Follow the below steps to “Enable” the custom script at the tenant level:
  • Login into your Office 365 Admin Portal.
    URL - https://admin.microsoft.com
    Click on ellipses in the left side panel.

    Note:  If you have Office 365 Germany, sign in at https://portal.office.de. If you have Office 365 operated by 21Vianet (China), sign in at https://login.partner.microsoftonline.cn/. Then select the Admin tile to open the admin center.
  • Then, it will display all the menu option in the panel. Scroll down and hover on "Admin" center menu and click on "SharePoint" as shown below image.
  • It will open the SharePoint admin page. In the left navigation, select 'Settings'.
  • It will navigate to the settings page. Scroll down till "Custom Script" section. In this select "Allow users to run a custom script on personal sites" & "Allow users to run a custom script on self-service created sites" as shown in below image:
  • Then scroll down to the end of the page and click “OK”. It will take about 24 hours for the changes to take effect.
 
Once these settings are implemented, you will have your classic SharePoint available same as you know. But this also enables the threat that we discussed in the first part. So we would not recommend this approach. 
So what is the alternative? Check out our last post of this topic for same. 

 Reference Link

Saturday, 16 March 2019

SharePoint Online Allow custom scripts - Part 1

Recently my office 365 trial expire and Microsoft suggests me to apply for new developer subscription due to my usage. So I set up a new office 365 tenant and try to migrate my test content from old tenant to new. But there I get an issue. The issue was the new tenant has custom scripts disabled.

Analysis:

When I searched for same, I found out due to a new modern site functionality Microsoft has to make changes in their environment and now each new tenant comes with scripting functionality disabled.


The reason behind disablening is that allowing javascript injection is big security concern. See below high level point that Microsoft provided:
  • Every script that runs in a SharePoint page always runs in the context of the user visiting the page and the SharePoint application. Scripts have access to everything the user has access to. With enough access, you can even delete site collection in back end while end user didn't know about it.
  • You can't audit the insertion of script.once you allow scripting, you can't identify What code has been inserted or Where the code has been inserted or Who inserted the code.
  • You can't block or remove inserted script. If you've allowed custom script, you can change the setting to later prevent users from adding custom script, but you can't block the execution of script that has already been inserted.
Why do we need to enable it when Microsoft has disabled scripting in the first place? Here are some of the reasons:

  • The main issue I face - users won't be able to copy items between SharePoint sites and between OneDrive and SharePoint
  • You are not allowed to save the site or list templates.
  • The solution gallery won't work. If you are using any sandbox solution then this is the required thing.
  • SharePoint Designer won't have full features available. Microsoft has listed that it will affect pages and list/library forms.
  • You will not able to upload code files with extensions .asmx, .ascx , .aspx , .htc , .jar , .master , .swf , .xap , .xsf in library.

  • Microsoft has listed below web parts that are not allowed when scripting is disabled
    • Business Data
      • Business Data Actions
      • Business Data Item
      • Business Data Item Builder
      • Business Data List
      • Business Data Related List
      • Excel Web Access
      • Indicator Details
      • Status List
      • Visio Web Access
    • Community
      • About This Community
      • Join
      • My Membership
      • Tools
      • What's Happening
    • Content Rollup
      • Categories
      • Project Summary
      • Relevant Documents
      • RSS Viewer
      • Site Aggregator
      • Sites in Category
      • Term Property
      • Timeline
      • WSRP Viewer
      • XML Viewer
    • Document Sets
      • Document Set Contents
      • Document Set Properties
    • Forms
      • HTML Form Web Part
    • Media and Content
      • Content Editor
      • Script Editor
      • Silverlight Web Part
    • Search
      • Refinement
      • Search Box
      • Search Navigation
      • Search Results
    • Search-Driven Content
      • Catalog-Item Reuse
    • Social Collaboration
      • Contact Details
      • Note Board
      • Organization Browser
      • Site Feed
      • Tag Cloud
      • User Tasks
  • Last limitation and the major one is you can't add/edit master pages and page layouts.

Solution:

I got another Microsoft blog that suggests what are the steps to revert changes if you need the old system. So I am sharing some of the points I discovered while setting up my tenant. I would like to give credit to Microsoft for such a detailed but simple article. Please see refernce links section for URL.

So why am I writing a blog on it? Because I just want to highlight some useful features I came across that are affected by this and if you are facing the same issues you can simply enable custom scripting. And even though the blog is detailed, it lacks some screenshots.
Please review my second blog on this topic for scripting code.

Reference Links

Thursday, 28 February 2019

SharePoint Supported Languages and Culture codes

Recently I needed to translate a site in Chinese for single user. Easy to implement - go to users user profile and set its preferred language to Chinese. And allow you site language to view in chines from site setting -> language settings. Right?

No. Because you will get 5 types of  Chinese language while in language settings there are two different options. So what to do. Below is SharePoint Supported Language and Culture codes that may come handy for such scenarios:


Language Name
Culture Name
Locale ID
Arabic
ar-sa
1025
Bulgarian
bg-bg
1026
Catalan
ca-es
1027
Chinese (Simplified)
zh-cn
2052
Chinese (Traditional, Taiwan)
zh-tw
1028
Croatian
hr-hr
1050
Czech
cs-cz
1029
Danish
da-dk
1030
Dutch
nl-nl
1043
English
en-us
1033
Estonian
et-ee
1061
Finnish
fi-fi
1035
French
fr-fr
1036
German
de-de
1031
Greek
el-gr
1032
Hebrew
he-il
1037
Hindi
hi-in
1081
Hungarian
hu-hu
1038
Italian
it-it
1040
Japanese
ja-jp
1041
Kazakh
kk-kz
1087
Korean
ko-kr
1042
Latvian
lv-lv
1062
Lithuanian
lt-lt
1063
Norwegian (Bokmål)
nb-no
1044
Polish
pl-pl
1045
Portuguese (Brazil)
pt-br
1046
Portuguese (Portugal)
pt-pt
2070
Romanian
ro-ro
1048
Russian
ru-ru
1049
Serbian (Latin)
sr-latn-cs
2074
Slovak
sk-sk
1051
Slovenian
sl-si
1060
Spanish
es-es
3082
Swedish
sv-se
1053
Thai
th-th
1054
Turkish
tr-tr
1055
Ukrainian
uk-ua
1058

Tuesday, 9 October 2018

Office 365 - Current login User Details

I generally needs to go to google each time to get current login User details for Office 365. Here is post for general idea how you can get the details in Office 365:

Approach 1 - Use Graph API

If you want to use Graph api, follow below steps,

  • go to below URL
    https://developer.microsoft.com/en-us/graph/graph-explorer
  • Sign in with your O365 details. 

  • Once you are logged in, click on "my profile" and it will get all your details.

How to use this in code,  I will write another blog for same.


Approach 2 - Use browser Console


Some of the properties are available using "_spPageContextInfo". Like user display name, user email address and user login name.

  • user display name - _spPageContextInfo.userDisplayName
  • user email - _spPageContextInfo.userEmail
  • user login name - _spPageContextInfo.userLoginName
  • user Id - _spPageContextInfo.userId
Approach 3 - Use Rest API (Ajax request)

To get other details you need to use below ajax request:

function getCurrUsrImg(){

var siteurl = _spPageContextInfo.webAbsoluteUrl;
        Var usrId = _spPageContextInfo.userId;
var userURL = siteurl + "/_api/web/SiteUserInfoList/Items('"+usrId+"')";
$.ajax({
url: userURL,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
async: true,
success: function (data) {
getCurrUserIMGSuccess(data.d);
},
error: function (data) {
console.log("Error: "+ data);
}
});
}

function getCurrUserIMGSuccess(res){
//console.log("llll");

var uHTMLIMG = "";
if(res.Picture != null){
uHTMLIMG = "<img src='"+res.Picture["Url"]+"'>";
}

$('#divCuserimg').html("");
$('#divCuserimg').html(uHTMLIMG);
}

You can get below list of fields with this call:

  • Id
  • ContentTypeId
  • Title (full name - love thakker)
  • Name (domain name - i:0#.f|membership|love.thakker)
  • EMail
  • MobilePhone
  • SipAddress
  • Deleted (true / false)
  • Picture ( look up - expand with description and URL)       
  • Department       
  • JobTitle        
  • FirstName        
  • LastName
  • WorkPhone      
  • UserName        
  • GUID   
  • Modified      
  • Created       
  • AuthorId
  • EditorId

Approach 4 - Use People Manager api (Ajax request)
If you want even more details than this then you can use below service call

$.ajax({  
  
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",  
            headers: { Accept: "application/json;odata=verbose" },  
            success: function (data) {  
                try {  
                    //Get properties from user profile Json response  
                    userDisplayName = data.d.DisplayName;  
                    AccountName = data.d.AccountName;  
                    var properties = data.d.UserProfileProperties.results;  
                    for (var i = 0; i < properties.length; i++) {  

                        var property = properties[i];  
                        if (property.Key == "Office") {  
location = property.Value;
                        }  

                    }
                } catch (err2) {  
                  console.log('error');
                }  
            },  
            error: function (jQxhr, errorCode, errorThrown) {  
                alert(errorThrown);  
            }  
        });  
        

}

Below is list of columns that you will get when you use this:
  • AccountName
  • DisplayName
  • Email
  • ExtendedManagers
  • ExtendedReports
  • Peers
  • PersonalSiteHostUrl (-my.sharepoint.com)
  • PersonalUrl (my.sharepoint.com/personal/love_thakker)
  • PictureUrl
  • Title
  • UserProfileProperties
    • UserProfile_GUID
    • SID
    • ADGuid
    • AccountName
    • FirstName
    • SPS-PhoneticFirstName
    • LastName
    • SPS-PhoneticLastName
    • PreferredName
    • SPS-PhoneticDisplayName
    • WorkPhone
    • Department
    • Title
    • SPS-Department
    • Manager
    • AboutMe
    • PersonalSpace
    • PictureURL
    • UserName
    • QuickLinks
    • WebSite
    • PublicSiteRedirect
    • SPS-JobTitle
    • SPS-DataSource
    • SPS-MemberOf
    • SPS-Dotted-line
    • SPS-Peers
    • SPS-Responsibility
    • SPS-SipAddress
    • SPS-MySiteUpgrade
    • SPS-DontSuggestList
    • SPS-ProxyAddresses
    • SPS-HireDate
    • SPS-DisplayOrder
    • SPS-ClaimID
    • SPS-ClaimProviderID
    • SPS-LastColleagueAdded
    • SPS-OWAUrl
    • SPS-ResourceSID
    • SPS-ResourceAccountName
    • SPS-MasterAccountName
    • SPS-UserPrincipalName
    • SPS-O15FirstRunExperience
    • SPS-PersonalSiteInstantiationState
    • SPS-DistinguishedName
    • SPS-SourceObjectDN
    • SPS-LastKeywordAdded
    • SPS-ClaimProviderType
    • SPS-SavedAccountName
    • SPS-SavedSID
    • SPS-ObjectExists


Thursday, 13 September 2018

Multi line column data Format issue in Document Library SharePoint

Recently, we need to show data from Document library to a classic view page. We get rest call. Get data. Display on page. Task done. Easy right? No. There was a multi line column which was showing data as row text. Also that column has 255 character limit. How can this be?

Analysis:
We got a tech net page which says multi line is not same in list and library. So we won't get rich text or enhance rich text option in that. Only plain text available.

Reference - https://social.msdn.microsoft.com/Forums/office/en-US/67a70245-cd03-48e1-b0fa-71bbb6a7744d/is-enhanced-rich-text-column-supported-by-document-library?forum=sharepointcustomizationlegacy

Solution:

So there were two issue. And below are solution for same:


  • Getting 255 character limit.
So open column and set settings to allow unlimited text. It will fix this issue.




  • Show multi line data as formatted.
For this you need to use "<Pre>"tag. It will show data in same way the text is entered in column.

Code sample:



$(document).ready(function(){
$.ajax({     
url:_spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getByTitle('Newsletter')/items?$select=DocIcon,EncodedAbsUrl,FileLeafRef,Editor/Title,Highlighted_x0020_Content&$expand=Editor&$orderby=FileLeafRef desc",
    type: "GET",  
    headers: {  
        "accept": "application/json;odata=verbose",  
        "content-Type": "application/json;odata=verbose"  
    },  
    success: function(data) {  
var html="";
for(i=0;i<data.d.results.length;i++){
var currentData = data.d.results[i];
var previewPath = _spPageContextInfo.webAbsoluteUrl +"/_layouts/15/getpreview.ashx?path="+ currentData.EncodedAbsUrl;
var highlightedContent = currentData.Highlighted_x0020_Content!= null ? currentData.Highlighted_x0020_Content:"";
var docType = currentData.DocIcon;
var imgdoc;
        html+="<div class='parentDiv'><div class='titleDiv'>"+currentData.FileLeafRef+"</div><div class='editDiv'></div><div class='contentDiv'><pre>"+highlightedContent +  "</pre></div></div>";
}
$("#NewsLetter").html(html);
    },  
    error: function(error) {  
        console.log(JSON.stringify(error));  
    }  
}); 
})

Friday, 24 August 2018

List ribbon not load issue in Office 365

Issue:
Recently, we have a strange issue. The list was not showing ribbon tabs default. There are many reasons I found for this behavior, like

  • Permission issue - we have site collection access
  • custom script to stop ribbon load - we have checked there was no custom coding done.

Then we found a blog stating that even if you add any custom webpart in list / library page, the ribbon lost its focus from main webpart. So it won't show. Andd it was true. we have added a legal text in our list heading using content editor webpart.

Solution:

So what is solution to bring it back? Below is code sample that we added in our page for loading ribbon tab on page load.

Code:
window.onload = function(){
  var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
  if (elem != null) {
      var dummyevent = new Array();
      dummyevent["target"] = elem;
      dummyevent["srcElement"] = elem;
      elem.parentNode.click();
      WpClick(dummyevent);
   }
//code to click browse button
   document.getElementsByClassName("ms-cui-tt-span")[0].click();
   }

Wednesday, 8 August 2018

HTML 5 Video tag

As always, I was working on a project which contains bugs. but this time a video was issue. Issue was video was playing in most of browser but not in Internet Explorer. As a part of analysis I found that client was using some third party browser to render video.

So I checked alternative for that. And what I get is HTML 5 video tag. Below is code that I used for testing:

<html>
<head>
</head>
<body>
<video controls autoplay loop>
  <source src="https://www.w3schools.com/tags/movie.mp4" type="video/m4v">
Your browser does not support the video tag.
</video>
</body>
</html>

Few things that it provides is very good. for example, below attributes

  • Autoplay - if you add this in video tag, video will start automatically. 
  • Loop - Provides a way to play video continuously.
You can check other attributes as well in reference link below.

Our client was using "M4a" format. But video tag supports below formats only. So we change our video format in "MP4"
  • MP4 - This only is supported in IE, Chrome and Firefox.
  • WebM
  • Ogg

Note: The video tag is not supported in Internet Explorer 8 and earlier versions.

As it solved my problem, I thought its worth sharing for my future reference and it my help you.

Reference:
https://www.w3schools.com/tags/tag_video.asp