1

We are running the same simple web.get_lists().getById("id") script in two distinct markup pages. It works fine in both pages, except when it comes to a Managed Metadata Taxonomy Field: enumerator.get_current().get_item("TaxField") returns differently:

  • in Page A Sharepoint Markup: a "human readable" object
  • in Page B Pure HTML Markup: a raw "machine readable" object

Relevant code as follows. Any thoughts on why or what references are missing?

PAGE A (Sharepoint Markup) script portion return:

//console.log(currentListItem.get_item('TaxonomyField'))
 Object {
 Label: "MyTermLabel",
 TermGuid: "23875525-01c7-42ad-9a89-bf4e9dd864de",
 WssId: 2,
 _ObjectType_: "SP.Taxonomy.TaxonomyFieldValue"}

PAGE B (Pure HTML Markup) script portion return:

//console.log(currentListItem.get_item('TaxonomyField'))
SP.Taxonomy.TaxonomyFieldValue {
    $0_1: "MyTermLabel", 
    $1_1: "23875525-01c7-42ad-9a89-bf4e9dd864de", 
    $2_1: 2}

My.js script portion

var list = web.get_lists().getById(reflected.SP.Web.List.MyList);
var query = new SP.CamlQuery();
query.set_viewXml("<xml...>"); //shortned for this purpose
var items = list.getItems(query);
ctx.load(list);
ctx.load(items);
ctx.executeQueryAsync(Function.createDelegate(this,function(){
    var enumerator = items.getEnumerator();
    while (enumerator.moveNext()) {
        var currentListItem = enumerator.get_current();
        console.log(currentListItem.get_item('TaxonomyField'))
     }),
     Function.createDelegate(this,function(err){}));

PAGE A (Sharepoint Markup)

<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.js"></script><script type="text/javascript" src="/_layouts/15/sp.taxonomy.js"></script>

    <script type="text/javascript" src="../Scripts/Angular/core/angular.js"></script>
    <script type="text/javascript" src="../Scripts/Angular/My.js"></script>
</asp:Content>

PAGE B (PURE HTML Markup)

    <!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title></title>

        <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="https://static.sharepointonline.com/bld/_layouts/15/16.0.5018.1212/msajaxbundle.js"></script>

        <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
        <script type="text/javascript" src="/_layouts/15/sp.js"></script>
        <script type="text/javascript" src="/_layouts/15/sp.taxonomy.js"></script>    

        <script type="text/javascript" src="../Scripts/Angular/core/angular.js"></script>
        <script type="text/javascript" src="../Scripts/Angular/My.js"></script>
    </head>
  • Random guess, would have to test out: the "human readable" format you see in the SharePoint markup page is dependent in some way or another on some libraries that are defined in the masterpage. The second page does not use the masterpage, so it is missing some component that operate the "transformation" you see. – SPArchaeologist Mar 8 '16 at 19:20
  • yes, that's what I am trying to identify! Think I gonna edit the post to be more assertive, tks @SPArchaeologist – egidiocs Mar 8 '16 at 19:50
  • i'm using this temp workaround. I realy don't like to modify the OM. "mySP":{"TaxonomyFieldValue": { "Label": "$0_1", "TermGuid": "$1_1" }} return (Object.Label || Object[mySP.TaxonomyFieldValue.Label]); – egidiocs Mar 8 '16 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.