Nintex Form - working with managed metadata fields

 

This is a post I wrote late last year, and applies to the Managed Metadata Fields in Nintex Forms via some "JavaScript middle-tier magic". 

 

Disclaimer

My conversations with the Nintex Form team back then was that at some point they might stop using the SharePoint Managed Metadata Fields and switch to their own control (similar to what they do with the people picker).  Then the following JavaScript code around Managed Metadata fields would stop working.

 

Goals

Nintex has a JavaScript wrapper API (NF.PeoplePickerAPI) around their People Picker Control.

Create something similar that allows me to wrap a Managed Metadata Field.

 

SPG.ManagedMetadataApi

 

(function (SPG, $, undefined) {

    var ctor = function (elem) {
        this.$elem = $(elem);

        var $taxonomyEditor = this.$elem.find(".ms-taxonomy");
        if ($taxonomyEditor.length) {
            this.controlObject = new Microsoft.SharePoint.Taxonomy.ControlObject($taxonomyEditor.get(0));
        }
    };

    ctor.prototype = {

        replaceTerm: function(label, termGuid) {
            var self = this;
            if (self.controlObject == undefined) return;

            var term = new Microsoft.SharePoint.Taxonomy.Term(label + "|" + termGuid);
            self.controlObject.replaceTerm(term);
        },

        clear: function() {
            var self = this;
            self.setRawText("");
        },

        setRawText: function (text) {
            var self = this;
            if (self.controlObject == undefined) return;

            self.controlObject.enableControl(true);
            self.controlObject.setRawText(text);
            self.controlObject.retrieveTerms();
            self.controlObject.validateAll();
        }
    };

    SPG.ManagedMetadataApi = ctor;
})(window.SPG = window.SPG || {}, NWF$);

 

Usage

 

  • List: My List
  • Field: MMField

 

/*
    using "normal" GET REST request doesn't bring back ManagedMetaDataFields, this is a workaround.
    https://social.msdn.microsoft.com/Forums/sharepoint/en-US/92cccd65-ba4c-4870-a858-7cd0e38a0482/how-can-i-use-caml-queries-with-the-rest-api
    because GetItems is a method on the List, this needs to be a POST operation.
*/

var url = _spPageContextInfo.webAbsoluteUrl +
    "/_api/Web/Lists/getByTitle('My List')/GetItems(query=@v1)" +
    "?@v1={'ViewXml':'<View><Query><Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">" + siteID +  
    "</Value></Eq></Where></Query></View>'}";

var promise = NWF$.ajax({
    type: "POST",
    url: url,
    headers: {
        "accept": "application/json;odata=verbose",
        "X-RequestDigest": NWF$("#__REQUESTDIGEST").val()
    },
    contentType: "application/json;odata=verbose",
    dataType: "json",
    cache: false,
    processData: true
});

promise.done(function (data) {

    var row = data.d.results[0];

    // similar syntax as NF.PeoplePickerApi
    var $mmField = new SPG.ManagedMetadataApi("#" + fieldMMField);
    $mmField.clear();
    if (row.MMField) {
        $mmField.replaceTerm(row.MMField.Label, row.MMField.TermGuid);
    }
});

SharePoint 2016 - debunking confusion and concerns

 

The announcement of SharePoint 2016 should not come as a surprise (Office 2016 was previously announced, and SharePoint has always been a product released in parallel).

http://blogs.office.com/2015/02/02/evolution-sharepoint/

What was the surprise, to me, is how many people immediately jump the gun and asks is there another version of SharePoint after 2016, I don't recall a time where when Microsoft announces Office 2010 is coming and people immediately ask is there an Office 2013.

 

Why the confusion

 

I think the confusion, or concern, is that customers can clearly see Microsoft's heavy investment in Office 365, and even the attitude of cannibalizing its own existing products to move forward. 

I think this is the right thing to do for Team Office.  Apple let iPhone ate the iPod.  Windows didn't evolve and got stagnant.

But our concern is genuine.  Many customers can not move to the cloud.  They are indeed worried whether they should continue spending in the on-premises product, or invest elsewhere.  It seems that Microsoft has not been investing in existing features, instead it has been investing only in Office 365 and very little is coming down the pike.

There are also much FUD spread by competitors implying Microsoft has abandoned on-premises and thus a customer should consider abandoning Microsoft and go with a competing on-premises product.

 

What we can safely assume

 

There are areas that Microsoft is playing to its strengths.  Many companies - Facebook for Work, Google Apps - are entirely cloud (or mobile) offerings.  SharePoint and Office 365 is a hybrid offering.  And in this strength, Microsoft is uniquely in the cloud, but also in your enterprise and cross-platform in your devices.  This isn't going to change, in fact, this is an area Microsoft will continue to expand the offering.

A decade ago, we can distil Microsoft and Windows down to A PC on Every Desktop

I'd like to think that for Team Office, it should be Office anywhere you do Work.

This means that perhaps while SharePoint the brand is fading into an on-premises only product, SharePoint the product is never going away.  It has not been given the 10-year support life line.  And Microsoft continues to invest in the product.

 

What could the next version of SharePoint look like?

 

I see two possibilities with the shape of the next version of SharePoint. 

It could be a stand alone product, in the shape of SharePoint 2019, launched with Office 2019 desktop suite.

It is also possible that in the SharePoint 2016 timeframe, the product becomes Evergreen and future updates are rolled out in the form of Service Packs.

 

I would kiss the Microsoft Product Manager that makes SharePoint On-Premises Evergreen.  This isn't something unimaginable.  Office 365 has already gone that route.  Windows 10 is envisioned as Windows as a Service and new updates will just roll out new features.  An Evergreen SharePoint effectively means this would be the last release version of SharePoint - and that is great for customers.

It's worthwhile to note that this isn't a decision Team Office has to make in the 2015-2016 timeframe.  This is a decision that should be made in the 2016-2018 timeframe.  By that time, Microsoft and customers would be well-understood about what Microsoft means when it says Windows As A Service.

 

So no rush.  But you know what I want, Dear Team-Office-Santa.

 

What I want to see more

 

http://blogs.microsoft.com/firehose/2015/02/02/how-sharepoint-will-evolve-in-the-cloud-with-office-365/

Reading between the lines in the Office announcement, I think Office 365/SharePoint announcements coming up in Ignite will be split into really three areas:

  • Office 365 / Cloud / SaaS - new features will appear here first.  That's what Cloud-First means.
  • SharePoint 2016 - boring backend updates, applicable learnings from Office 365 (probably not much - since we aren't big on hosting multi-tenanted environments in a single enterprise).  Database stuff.  High availability.  API updates and APPs that runs in the cloud but also on premises.
  • Hybrid, Hybrid, Hybrid - how to connect everything from Office 365 with On-premises SharePoint: Sway.  Video Portals.  The mystical "Next Generation Portals", Yammer, Groups, Delve and Hybrid Search. 

 

I expect news to be a bit light between now and Ignite conference, where Microsoft is storing up bags of product announcement goodies.

http://ignite.microsoft.com/

 

I'm preparing for everything to get more awesome.  And I don't think SharePoint is going away anytime soon.  If anything, it is still right in the middle of everything (if you are on the ground, not just in the cloud).

 

I'm Loving every bit of it.  Turn it up to v15!

So, this is what can happen if you hack SP javascript files

 

SharePoint 2010's April 2014 CU introduced a bug with copy and paste. 

Bform.debug.js 381,869 11-Feb-2014 12:37
Bform.js 249,012 30-Jan-2014 16:39
Form.debug.js 211,134 11-Feb-2014 12:37
Form.js 126,783 30-Jan-2014 16:39

 

This was fixed and released in SharePoint 2010's August 2014 CU.
http://support.microsoft.com/kb/2760757

Bform.debug.js 381,888 15-Jul-2014 11:17
Bform.js 249,022 15-Jul-2014 11:17
Form.debug.js 211,153 15-Jul-2014 11:17
Form.js 126,793 15-Jul-2014 11:17

 

Story

On December 10, 2014, before we patched to the August 2014 CU level.  A certain very naughty person (me) couldn't wait and decided to offer a quick hack to the Javascript for the users over the holidays.  He even did a bak backup file of the original Form.js

 

image

 

We have now applied the August patch, but unfortunately, you can see:

bform.js, bform.debug.js, form.debug.js all updated.

Form.js is NOT updated.

Copy and paste still doesn't work in our environment.

 

Oops.

 

While a cheating way would be that we install the patch on another environment, and copy the correct Form.js file over. 

We'll be experimenting in this dev environment to see what is the best way to revert and go back to the supported path.  Stay tuned for a follow up article.

SPD2013 Workflow - how to check user is member of group

 

I want to describe a method that I use to check if a user is a member of a group.

 

Steps

  • Call a REST webservice
    • Reference MSDN for the correct API
    • Build a RequestURL and a basic RequestHeader
    • Figure out what the results mean
  • Wrap it up in a Workflow Custom Activity

 

API

MSDN (http://msdn.microsoft.com/en-us/library/office/dn268594(v=office.15).aspx - this needs to be a SharePoint Developer's home page) documents a few REST end points that I use for this.

http://msdn.microsoft.com/en-us/library/office/dn531432(v=office.15).aspx#bk_Group

Says you can get to a sharepoint group via:

  • http://<site url>/_api/web/sitegroups(<group id>)
  • http://<site url>/_api/web/sitegroups(<group name>)

The group also has a Users property that points to a Users Collection.

http://msdn.microsoft.com/en-us/library/office/dn531432(v=office.15).aspx#bk_UserCollection

This expands our example to:

  • http://<site url>/_api/web/sitegroups(<group id>)/users

For example:

 

The Users Collection does not have a method for testing if a user exists.  So I've taken the shortcut and basically brute force the service and just try to retrieve a user.  If you try to request a user that doesn't exist in the collection, it will just error, and I just catch that error.

 

SharePoint Designer workflow

 

image

 

Build Request Header

image

Both Accept and Content-Type needs to be "application/json;odata=verbose"

 

Build Request URL

image

Concatenate Current Site URL (which ends without a trailing /) and the earlier API.

Note my group name is 'john Members'

 

Call Web Service

image

 

Catch and process the result value.

image

 

The ResponseCode could be either OK or InternalServerError

Get a property from the returned Response variable "d/Title" would correspond to the Display Name of the user returned.  If the ResponseCode was Error, then there would be no value in the Response object.

 

 

Sandbox Custom Workflow Activity

 

In Visual Studio, these activities can be bundled into one single Activity that can be reused in SharePoint Designer.  I'll update this in a future blog post on Visual Studio.

 

 

Thoughts on checking nested group or AD group memberships

  • There are no way to check member with nested groups.  One possibility is to not think of it as membership, but think of it as whether the person has a certain permission.

    Does the current user have permission to do Contribute on the current Site. 
  • A more complicated thinking could be to create a list, kick out everyone except the group you are interested in, and check if the current user has permission to that list.

 

 

This Example in JavaScript

 

The more I work with SharePoint 2013 Workflows the closer parallels I see relating to a traditional programming language.  Here's the same function call in Javascript.

var promise = $.ajax({
        type: "GET",
        url: _spPageContextInfo.siteServerRelativeUrl + "/_api/web/sitegroups/getbyname('john Owners')/users/getbyid(" + _spPageContextInfo.userId + ")",
        headers: {
                "accept": "application/json;odata=verbose"
        },
        contentType: "application/json;odata=verbose",
        dataType: "json",
        cache: false,
        processData: true
});

promise.then(
        function (data, status) {

                if (status == "success" && data && data.d) {
                        var title = d.Title;

                }
                else {
                    // success, but no records - this can't really happen.
                }
        },
        function () {
                // not successful - usually not a member of that group
        }
);

SharePoint Saturday Sydney 2014

November 29, 2014 was a great day for SharePoint Saturday.

I presented "Develop and Build Workflow Apps in SP2013. Wait, Workflow Apps?" - which is a session that covers lots of the new things you can build with SharePoint 2013 workflows using primarily Visual Studio 2013.  These work on premises and in Office 365.

 

The REST end points opens up SharePoint

 

I still think my transition along with exploring new activity and suddenly jumping into REST was tough.  I need to work on how to introduce that point.

The key point stands.  As a developer, or even a power user using Workflows - the REST API opens SharePoint completely to me.  I can use it to create lists, site columns or assign permission groups.  The trouble is that creating the JSON packet to talk to SharePoint end point is quite hard.  Which is why the need (and the ability) to package existing series of Actions into a reusable Custom Activity is a big deal.

 

Confusion over Workflow Custom Activity

 

There was actually a lot of confusion over the artefact "Custom Activity".  In 2010, these were sandbox or coded solutions.  In 2013, Custom Activity is completely declarative.  It is a way for you to save a series of workflow actions into a reusable piece of functionality that you can use over and over.  In my demo project I have about 10 custom activities.

 

Downloads

 

 

News Update

 

We announced at the beginning and the end of SharePoint Saturday 2014 that this would be the last SharePoint Saturday in Australia.  As Microsoft and Industry trends towards Office 365, we will move with that trend.

From 2015 onwards, Office 365 Saturday will return, bigger and with more coverage of Office and SharePoint Online, but also address your On Premises needs.

Hope you have a great holidays and see you soon in 2015!