rantings and ravings of a technology based solutionist

Switch SharePoint 2013 Page Language to User Preferred Language using JavaScript/jQuery

When users set their language preferences within their My Site, many expect translation to occur across all of SharePoint. The reality is that this will change certain aspects of SharePoint, but not page text or content within custom Web Parts. While the multi-lingual aspects of SharePoint 2013 are robust (variations, machine translation, etc.), there is a core limitation that affects the switch to the user language.

If you open the developer tools in IE, you will find that SharePoint sets the page language to English (ex. html lang=”en-US”) by default even if your preferred language is different. This is highly problematic if you, for example, serve up both English and Spanish content to one page and only show the content via the language you want. This requires some CSS tagging, but is a nice option versus a full site variation.

To accomplish the switch, I developed the following script, which can be run via the XML Viewer Web Part method mentioned here. This script provides a dictionary of key/value pairs for each LCID referenced by Microsoft, detects the users preferred language, appends an ID to the core <html> tag for reference, and then changes to the preferred language. All of these activities occur post DOM load, as the default language tag of “en-US” needs to be set first.

¡buena suerte!

HTML file/code to be referenced by XML Viewer Web Part (I placed the JavaScript and HTML file in SiteAssets):

<?xmlversion="1.0"encoding="utf-8"?> <!--Supporting JavaScript Files--> <scriptsrc="../SiteAssets/switchLanguage.js"></script>

JavaScript file/code referenced by HTML file:

SP.SOD.executeFunc("sp.js", 'SP.ClientContext', switchLanguage);
function switchLanguage() {     var language = {         54: 'af',         1078: 'af-ZA',         28: 'sq',         1052: 'sq-AL',         132: 'gsw',         1156: 'gsw-FR',         94: 'am',         1118: 'am-ET',         1: 'ar',         5121: 'ar-DZ',         15361: 'ar-BH',         3073: 'ar-EG',         2049: 'ar-IQ',         11265: 'ar-JO',         13313: 'ar-KW',         12289: 'ar-LB',         4097: 'ar-LY',         6145: 'ar-MA',         8193: 'ar-OM',         16385: 'ar-QA',         1025: 'ar-SA',         10241: 'ar-SY',         7169: 'ar-TN',         14337: 'ar-AE',         9217: 'ar-YE',         43: 'hy',         1067: 'hy-AM',         77: 'as',         1101: 'as-IN',         29740: 'az-Cyrl',         2092: 'az-Cyrl-AZ',         44: 'az',         30764: 'az-Latn',         1068: 'az-Latn-AZ',         69: 'bn',         2117: 'bn-BD',         1093: 'bn-IN',         109: 'ba',         1133: 'ba-RU',         45: 'eu',         1069: 'eu-ES',         35: 'be',         1059: 'be-BY',         25626: 'bs-Cyrl',         8218: 'bs-Cyrl-BA',         26650: 'bs-Latn',         30746: 'bs',         5146: 'bs-Latn-BA',         126: 'br',         1150: 'br-FR',         2: 'bg',         1026: 'bg-BG',         85: 'my',         1109: 'my-MM',         3: 'ca',         1027: 'ca-ES',         146: 'ku',         31890: 'ku-Arab',         1170: 'ku-Arab-IQ',         92: 'chr',         31836: 'chr-Cher',         1116: 'chr-Cher-US',         4: 'zh-Hans',         30724: 'zh',         2052: 'zh-CN',         4100: 'zh-SG',         31748: 'zh-Hant',         3076: 'zh-HK',         5124: 'zh-MO',         1028: 'zh-TW',         131: 'co',         1155: 'co-FR',         26: 'bs, hr, or sr',         1050: 'hr-HR',         4122: 'hr-BA',         5: 'cs',         1029: 'cs-CZ',         6: 'da',         1030: 'da-DK',         140: 'prs',         1164: 'prs-AF',         101: 'dv',         1125: 'dv-MV',         19: 'nl',         2067: 'nl-BE',         1043: 'nl-NL',         9: 'en',         3081: 'en-AU',         10249: 'en-BZ',         4105: 'en-CA',         9225: 'en-029',         15369: 'en-HK',         16393: 'en-IN',         6153: 'en-IE',         8201: 'en-JM',         17417: 'en-MY',         5129: 'en-NZ',         13321: 'en-PH',         18441: 'en-SG',         7177: 'en-ZA',         11273: 'en-TT',         2057: 'en-GB',         1033: 'en-US',         12297: 'en-ZW',         37: 'et',         1061: 'et-EE',         56: 'fo',         1080: 'fo-FO',         100: 'fil',         1124: 'fil-PH',         11: 'fi',         1035: 'fi-FI',         12: 'fr',         2060: 'fr-BE',         11276: 'fr-CM',         3084: 'fr-CA',         9228: 'fr-CD',         12300: 'fr-CI',         1036: 'fr-FR',         15372: 'fr-HT',         5132: 'fr-LU',         13324: 'fr-ML',         14348: 'fr-MA',         6156: 'fr-MC',         8204: 'fr-RE',         10252: 'fr-SN',         4108: 'fr-CH',         98: 'fy',         1122: 'fy-NL',         103: 'ff',         31847: 'ff-Latn',         2151: 'ff-Latn-SN',         86: 'gl',         1110: 'gl-ES',         55: 'ka',         1079: 'ka-GE',         7: 'de',         3079: 'de-AT',         1031: 'de-DE',         5127: 'de-LI',         4103: 'de-LU',         2055: 'de-CH',         8: 'el',         1032: 'el-GR',         111: 'kl',         1135: 'kl-GL',         116: 'gn',         1140: 'gn-PY',         71: 'gu',         1095: 'gu-IN',         104: 'ha',         31848: 'ha-Latn',         1128: 'ha-Latn-NG',         117: 'haw',         1141: 'haw-US',         13: 'he',         1037: 'he-IL',         57: 'hi',         1081: 'hi-IN',         14: 'hu',         1038: 'hu-HU',         15: 'is',         1039: 'is-IS',         112: 'ig',         1136: 'ig-NG',         33: 'id',         1057: 'id-ID',         93: 'iu',         31837: 'iu-Latn',         2141: 'iu-Latn-CA',         30813: 'iu-Cans',         1117: 'iu-Cans-CA',         60: 'ga',         2108: 'ga-IE',         16: 'it',         1040: 'it-IT',         2064: 'it-CH',         17: 'ja',         1041: 'ja-JP',         4096: 'jv',         4096: 'jv-Latn',         4096: 'jv-Latn-ID',         134: 'qut',         1158: 'qut-GT',         75: 'kn',         1099: 'kn-IN',         63: 'kk',         1087: 'kk-KZ',         83: 'km',         1107: 'km-KH',         135: 'rw',         1159: 'rw-RW',         65: 'sw',         1089: 'sw-KE',         87: 'kok',         1111: 'kok-IN',         18: 'ko',         1042: 'ko-KR',         64: 'ky',         1088: 'ky-KG',         84: 'lo',         1108: 'lo-LA',         38: 'lv',         1062: 'lv-LV',         39: 'lt',         1063: 'lt-LT',         31790: 'dsb',         2094: 'dsb-DE',         110: 'lb',         1134: 'lb-LU',         47: 'mk',         1071: 'mk-MK',         4096: 'mg',         4096: 'mg-MG',         62: 'ms',         2110: 'ms-BN',         1086: 'ms-MY',         76: 'ml',         1100: 'ml-IN',         58: 'mt',         1082: 'mt-MT',         129: 'mi',         1153: 'mi-NZ',         122: 'arn',         1146: 'arn-CL',         78: 'mr',         1102: 'mr-IN',         124: 'moh',         1148: 'moh-CA',         80: 'mn',         30800: 'mn-Cyrl',         1104: 'mn-MN',         31824: 'mn-Mong',         2128: 'mn-Mong-CN',         4096: 'nqo',         4096: 'nqo-GN',         97: 'ne',         2145: 'ne-IN',         1121: 'ne-NP',         20: 'no',         31764: 'nb',         1044: 'nb-NO',         30740: 'nn',         2068: 'nn-NO',         130: 'oc',         1154: 'oc-FR',         72: 'or',         1096: 'or-IN',         114: 'om',         1138: 'om-ET',         99: 'ps',         1123: 'ps-AF',         41: 'fa',         1065: 'fa-IR',         21: 'pl',         1045: 'pl-PL',         22: 'pt',         4096: 'pt-AO',         1046: 'pt-BR',         2070: 'pt-PT',         1281: 'qps-ploc',         1534: 'qps-ploca',         2559: 'qps-plocm',         70: 'pa',         31814: 'pa-Arab',         1094: 'pa-IN',         2118: 'pa-Arab-PK',         107: 'quz',         1131: 'quz-BO',         2155: 'quz-EC',         3179: 'quz-PE',         24: 'ro',         2072: 'ro-MD',         1048: 'ro-RO',         23: 'rm',         1047: 'rm-CH',         25: 'ru',         1049: 'ru-RU',         133: 'sah',         1157: 'sah-RU',         28731: 'smn',         9275: 'smn-FI',         31803: 'smj',         4155: 'smj-NO',         5179: 'smj-SE',         59: 'se',         3131: 'se-FI',         1083: 'se-NO',         2107: 'se-SE',         29755: 'sms',         8251: 'sms-FI',         30779: 'sma',         6203: 'sma-NO',         7227: 'sma-SE',         79: 'sa',         1103: 'sa-IN',         145: 'gd',         1169: 'gd-GB',         27674: 'sr-Cyrl',         7194: 'sr-Cyrl-BA',         12314: 'sr-Cyrl-ME',         10266: 'sr-Cyrl-RS',         3098: 'sr-Cyrl-CS',         28698: 'sr-Latn',         31770: 'sr',         6170: 'sr-Latn-BA',         11290: 'sr-Latn-ME',         9242: 'sr-Latn-RS',         2074: 'sr-Latn-CS',         108: 'nso',         1132: 'nso-ZA',         50: 'tn',         2098: 'tn-BW',         1074: 'tn-ZA',         4096: 'sn',         4096: 'sn-Latn',         4096: 'sn-Latn-ZW',         89: 'sd',         31833: 'sd-Arab',         2137: 'sd-Arab-PK',         91: 'si',         1115: 'si-LK',         27: 'sk',         1051: 'sk-SK',         36: 'sl',         1060: 'sl-SI',         119: 'so',         1143: 'so-SO',         48: 'st',         1072: 'st-ZA',         10: 'es',         11274: 'es-AR',         8202: 'es-VE',         16394: 'es-BO',         13322: 'es-CL',         9226: 'es-CO',         5130: 'es-CR',         7178: 'es-DO',         12298: 'es-EC',         17418: 'es-SV',         4106: 'es-GT',         18442: 'es-HN',         22538: 'es-419',         2058: 'es-MX',         19466: 'es-NI',         6154: 'es-PA',         15370: 'es-PY',         10250: 'es-PE',         20490: 'es-PR',         1034: 'es-ES_tradnl',         3082: 'es-ES',         21514: 'es-US',         14346: 'es-UY',         4096: 'zgh',         4096: 'zgh-Tfng-MA',         4096: 'zgh-Tfng',         29: 'sv',         2077: 'sv-FI',         1053: 'sv-SE',         90: 'syr',         1114: 'syr-SY',         40: 'tg',         31784: 'tg-Cyrl',         1064: 'tg-Cyrl-TJ',         95: 'tzm',         31839: 'tzm-Latn',         2143: 'tzm-Latn-DZ',         73: 'ta',         1097: 'ta-IN',         2121: 'ta-LK',         68: 'tt',         1092: 'tt-RU',         74: 'te',         1098: 'te-IN',         30: 'th',         1054: 'th-TH',         81: 'bo',         1105: 'bo-CN',         115: 'ti',         2163: 'ti-ER',         1139: 'ti-ET',         49: 'ts',         1073: 'ts-ZA',         31: 'tr',         1055: 'tr-TR',         66: 'tk',         1090: 'tk-TM',         2080: 'ur-IN',         34: 'uk',         1058: 'uk-UA',         46: 'dsb or hsb',         1070: 'hsb-DE',         32: 'ur',         1056: 'ur-PK',         128: 'ug',         1152: 'ug-CN',         30787: 'uz-Cyrl',         2115: 'uz-Cyrl-UZ',         67: 'uz',         31811: 'uz-Latn',         1091: 'uz-Latn-UZ',         2051: 'ca-ES-valencia',         42: 'vi',         1066: 'vi-VN',         82: 'cy',         1106: 'cy-GB',         136: 'wo',         1160: 'wo-SN',         120: 'ii',         1144: 'ii-CN',         106: 'yo',         1130: 'yo-NG',         52: 'xh',         1076: 'xh-ZA',         53: 'zu',         1077: 'zu-ZA'     };
    var currentUserLanguage = SP.PageContextInfo.get_currentLanguage();
    $.each(language, function (lcid, value) {         if (lcid == currentUserLanguage) {             var switchLanguage = value;             $("html").attr('id', 'pageHTML');             document.getElementById("pageHTML").setAttribute('lang', switchLanguage)         }     }); }

 

 

 

Windows 8.1 App – jQuery Version 2.1.0 causing HTML1701: Unable to add dynamic content errors

If you are developing Windows 8.1 Apps, it appears an issue with jQuery version 2.1.0 causes “HTML1701: Unable to add dynamic content…” errors. This occurs even if jQuery code is not in use, but merely the link to jQuery is included in your code. Switching to jQuery 2.0.2 resolved the issue for me. The errors were as follows:

HTML1701: Unable to add dynamic content ”. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement.  For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.

HTML1701: Unable to add dynamic content ”. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement.  For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.

I am sure that this issue will be resolved, but in the meantime, I hope this helps others who may come across these error messages.

 

Using the SharePoint 2013 Trending Tags Web Part Outside of My Sites

Bernado Nguyen-Hoan has found an easy to follow method for using the Trending Tags Web Part outside of My Sites. You can view his post here:

http://bernado-nguyen-hoan.com/2013/03/05/using-trending-tags-web-part-outside-of-mysites/#comment-1305

The one challenge I faced was that since I needed to work in SharePoint 2013 Online, and am hesitant about activating the My Site Host feature, I would get errors when someone clicked on a hashtag related to a missing display template.

However, Bernado had an excellent suggestion of copying the  Control_Tagfeed.html display template from a My Site and uploading this to the non-My Site destination I needed to use it in. The display template is found in the Master Page Gallery via the following path:

Site Settings > Web Designer Galleries > Master Pages > Display Templates > System

You then copy the Control_Tagfeed.html file to the Master Page Gallery in your destination Site Collection. Please note that only the HTML file is required, as SharePoint will generate the corresponding JavaScript file for you.

Happy tagging!

How to Apply Cumulative Updates and Service Packs to SharePoint 2010 and SharePoint 2013

Since the August 31, 2011 Cumulative Update, it is no longer required to install the SharePoint Foundation Cumulative Update before proceeding with SharePoint Server Cumulative Updates. This greatly eases the burden of applying Cumulative Updates and Service Packs.

The high level process for updating your SharePoint Farm is as follows:

1) Verify your current patch level by matching the Build Number using these instructions:

SharePoint 2010: http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=224

SharePoint 2013: http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=346

2) Download the applicable Cumulative Update (CU) or Service Pack. A good recommendation is to always be one CU behind the current release for production environments to avoid issues that may be introduced by a new CU. I would treat a Service Pack the same way in that you would wait until a CU is released after the Service Pack before proceeding. Please note that updates tend to be cumulative from a certain level of Service Pack. You can find the prerequisites listed in each KB article supporting a CU or Service Pack.

SharePoint 2010 Cumulative Updates are located here: http://technet.microsoft.com/en-us/sharepoint/ff800847.aspx

SharePoint 2013 Cumulative Updates are located here: http://technet.microsoft.com/en-us/sharepoint/jj891062.aspx

3) Copy the CU or Service Pack to each of the servers that have SharePoint installed. If you are following a best practices three-tier architecture, your SQL server does not require a CU or Service Pack since it does not have SharePoint installed on it.

IMPORTANT: It is highly recommended to test your update on your development/test farm before proceeding with updates to the production environment as you will want to ensure that the update proceeded as planned and that any custom development components or third-party solutions are fully operational.

4) Run the CU or Service Pack on each SharePoint server. I generally start with the Application Server that hosts Central Administration and run the CU on all Application Servers first before proceeding to the Web Front End Servers (WFE).

IMPORTANT: Do not run the SharePoint Products Configuration Wizard until all servers have had the CU or Service Pack installed and have been reset.

5) Reset each server

6) After the servers restart, run the SharePoint Products Configuration Wizard starting with the first Application server you installed in your SharePoint Farm (generally hosting Central Administration), all other Application Servers, and finally all Web Front End (WFE) Servers. In case of failure, please review the error log presented to determine the source and note that you may need to execute the psconfig command instead of wizard. There are times when simply re-running the wizard or psconfig will configure the server properly. Use the following instructions to run your Psconfig commands: http://technet.microsoft.com/en-us/library/cc263093(v=office.14).aspx

7) Reset each server

8) Verify the build number by using the following instructions:

SharePoint 2010: http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=224

SharePoint 2013: http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=346

jQuery in SharePoint 2013 Script Editor Web Part not Executing when Minimal Download Strategy (MDS) Enabled

A word of warning. If you have the Minimal Download Strategy (MDS) feature activated in your SharePoint 2013 site, you may have challenges executing jQuery from a Script Editor Web Part or in page code placement.

jQuery that is on page load seems to function, but if you try to execute from a button or click event, it will not execute and leave you with an undefined error tied to the function you attempted to execute. This may be due to the call to execute not being cached, while on page load jQuery events are. If this affects you, there are 2 1/2 options as follows:

1) Disable MDS and lose the benefits of caching

2) Edit the master page to include the jQuery references as listed in this post: http://www.gsoft.com/en/blog/sharepoint-2013-developing-with-the-new-mds-feature

2 1/2) Hope that Microsoft addresses this limitation with a hotfix or Cumulative Update

QuickTip: Get the Hex Code of a Color on a Webpage using Internet Explorer Developer Tools

If you need to retrieve the Hex Code of a color on a webpage, you can obtain it by using Internet Explorer Developer Tools. Here are the steps:

1) Open Internet Explorer and browse to the webpage you want (I am using IE10)

2) Open the Internet Explorer Developer Toolbar by selecting F12 on your keyboard

3) Under the “Tools” menu select “Show color picker”

4) Scroll over the desired element and left click to lock in your selection

5) Select “Copy and Close” to copy the Hex Code

Capacity Limits for SharePoint Server 2013 and SharePoint 2013 Online

When working within SharePoint 2013, it is critical to respect the software boundaries, thresholds, and limits of the platform. Please note that SharePoint Online is more generalized and focused towards storage.

SharePoint Server 2013 Software Boundaries and Limitations:
http://technet.microsoft.com/en-us/library/cc262787.aspx

SharePoint 2013 Online Software Boundaries and Limitations
http://office.microsoft.com/en-us/office365-sharepoint-online-enterprise-help/sharepoint-online-software-boundaries-and-limits-HA102694293.aspx

Bulk Creation of SharePoint Site Columns and Content Types with PowerShell: Part 3

This post is the third in a series detailing the creation of SharePoint Site Columns and Content Types via PowerShell. The series has three parts as follows:

Part 1: Bulk Creating Site Columns with PowerShell

Part 2: Bulk Creating Content Types with PowerShell

Part 3: Bulk Adding Site Columns to Content Types with PowerShell

Bulk Adding Site Columns to Content Types with PowerShell: Overview While the previous two posts focused to the creation of Site Columns and Content Types, one final step remains; the addition (or linking) of Site Columns to the appropriate Content Types. If you evaluate the amount of clicks it takes to manually add Site Columns for use by a Content Type, then multiply that by your total Content Types, it is clear to see how PowerShell can greatly ease this tedious task.

READ FULL POST at blogs.captechconsulting.com

Bulk Creation of SharePoint Site Columns and Content Types with PowerShell: Part 2

This post is the second in a series detailing the creation of SharePoint Site Columns and Content Types via PowerShell. The series has three parts as follows:

Part 1: Bulk Creating Site Columns with PowerShell

Part 2: Bulk Creating Content Types with PowerShell

Part 3: Bulk Adding Site Columns to Content Types with PowerShell

Bulk Creating Content Types with PowerShell: Overview While not as tedious as Site Column creation, manual Content Type creation produces enough workload to demand attention. Whether creating Content Types in the Content Type Hub, or in a decentralized manner across Site Collections, the click count more than warrants using an automated solution via PowerShell.

READ FULL POST at blogs.captechconsulting.com

Bulk Creation of SharePoint Site Columns and Content Types with PowerShell: Part 1

This post is the first in a series detailing the creation of SharePoint Site Columns and Content Types via PowerShell. The series has three parts as follows:

Part 1: Bulk Creating Site Columns with PowerShell

Part 2: Bulk Creating Content Types with PowerShell

Part 3: Bulk Adding Site Columns to Content Types with PowerShell

Bulk Creating Site Columns with PowerShell: Overview The process of manually creating Site Columns in SharePoint can be a tedious process, especially if you follow best practices and truncate the field name before re-editing the Site Column to allow for a friendly display name. This is done to ensure that the internal field name does not contain any spacing characters such as %20. By counting the clicks, you may quickly realize the onset of Carpal Tunnel and start looking for a more efficient method for creating Site Columns. This is where PowerShell comes to the rescue.

READ FULL POST at blogs.captechconsulting.com