This function demonstrate the use of Fetch to return the BusinessUnitName for the current user.
Thanks to Peter000000

function GetBusinessUnitName() {
    var lGetBusinessUnitName;

    var fetchXml = "<fetch mapping='logical'>" +
                   "<entity name='systemuser'>" +
                   "<attribute name='businessunitid' />" +
                   "<filter type='and'>" +
                   "<condition attribute='systemuserid' operator='eq-userid' />" +
                   "</filter>" +
                   "</entity>" +
                   "</fetch>";

            XrmSvcToolkit.fetch({
                fetchXml: fetchXml,
                async: false,
                successCallback: function (result) {
                    lGetBusinessUnitName =  result.entities[0].businessunitid.Name;
                },
                errorCallback: function (error) {
                    throw error;
                }
            });

    return lGetBusinessUnitName;
}

Last edited Dec 4, 2012 at 11:36 AM by georged, version 2

Comments

No comments yet.