JSOM SharePoint Online Create Term with custom shared and local properties

The sp.Taxonomy.js can be used to create a term in the taxonomy store. I wanted to create Shared Custom properties on the term. However the JavaScript library on MSDN  mentions only  the method setLocalCustomProperty which creates or updates a local custom property.

The SetCustomProperty is mentioned in MSDN to use in CSOM managed code to create or update shared custom property on a term. There is a lack of documentation how to use the method in JSOM.  Following the convention of method name in JavaScript ,i.e. camelCase , I called the  method on a term object in JavaScript and it worked.

term.setCustomProperty("ClientId",1234);

The JSOM code below provides a UI to specify the term to create. To test the code, copy and paste the code into a JavaScript file, upload the JavaScript file into the site and reference the JavaScript file from a Content Editor WebPart.

CreateTerm

When the button “Create Term” is clicked, the term is created with the shared and local custom property.

TermWithCustomProperties

 

SharePoint JSOM to update Document ID Settings

The Document ID Service feature is useful to tag unique Id to documents across site collection to make it easier to retrieve. A prefix can be specified to use when the unique Id is generated.

The document id settings is stored in the web property bag “docid_settings_ui” after the feature the activated.

The web property bag can be updated using JSOM to assign a prefix with XML snippet like below.

var docIdValue = ‘<?xml version=”1.0″ encoding=”utf-16″?><DocIdUiSettings xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt; <Prefix>’ + docIDPrefix + ‘</Prefix> <AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>’

webProperties.set_item(“docid_settings_ui”, docIdValue);

The full script can be copied from below and tested in a content editor web part.

After the script is loaded on a content editor webpart, the [Site Collection URL] and [Doc ID Prefix] needs to be filled before clicking on “Configure Doc ID Settings”.

ConfigureDocIdSettings_UI

If successful, the message will appear.

TagYourSite

Navigate to site settings> Document ID Settings to verify the prefix

DocIdSettingsPrefix

 

Project Server 2013 Make fields Read Only in PDP depending on SharePoint Groups the logged user belong to

I had a requirement depending on the SharePoint group the user belong some fields need to be read only.

The script below disable the field  “Project Code” on the PDP (Project Detail Page) if the user is not in the SharePoint group “Project Code”.

Copy the code snippet to a script editor web part in a PDP page.

jQuery.noConflict();

function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();
var currentUser = currentContext.get_web().get_currentUser();
currentContext.load(currentUser);

var allGroups = currentWeb.get_siteGroups();
currentContext.load(allGroups);

var group = allGroups.getByName(groupName);
currentContext.load(group);

var groupUsers = group.get_users();
currentContext.load(groupUsers);

currentContext.executeQueryAsync(OnSuccess,OnFailure);

function OnSuccess(sender, args) {
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;
break;
}
}
OnComplete(userInGroup);
}

function OnFailure(sender, args) {
OnComplete(false);
}
}

function IsCurrentUserHasContribPerms()
{
if (!jQuery(‘input[title=”Project Code”]’).prop(‘disabled’) )
{
console.log(jQuery(‘input[title=”Project Code”]’).prop(‘disabled’));
IsCurrentUserMemberOfGroup(“Project Code”, function (isCurrentUserInGroup) {
if(isCurrentUserInGroup)
{
jQuery(‘input[title=”Project Code”]’).prop(‘disabled’,false);
}
else
{
// alert(“user not in group”);
jQuery(‘input[title=”Project Code”]’).prop(‘disabled’,true);
}
});
}

}
ExecuteOrDelayUntilScriptLoaded(function(){setInterval(IsCurrentUserHasContribPerms, 250)}, ‘SP.js’);

SharePoint, Approve Selected List Items

SharePoint provides Out of the box JavaScript Libraries.

The List Views functions are described in the post with an example how to apply some of the functions

CountSelectedItems(ctx); return count of selected items in view

SelectRowByIndex(ctx,1,true); selects first item in list view

DeselectAllItems(ctx, tab.rows, false);deselects all items in view

SelectRibbonTab(“Ribbon.ListItem”,true); displays the listitem ribbon

The code below can be copied into a script editor web part on a list view page.

I created a list “Test Approve Items” with columns “Status”, and “Title” with 4 list items.

ListViewOperations.JPG

When “Select All” button is clicked, all items in the list view get selected.

When “Deselect All” is clicked, all items in the list view get deselected.

When “Show Ribbon” is clicked, the ribbon is shown

ribbon.JPG

When “Set Approve” is clicked after selected some items, the status changes to “Approve”.