Sample Code

Dec 4, 2012 at 10:01 AM

Some sample code for the fetch function. 

This function returns the BusinessUnitName for the current user.

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;
}
Coordinator
Dec 4, 2012 at 10:25 AM

This is a very good example, I'll copy it to the documentation, if you don't mind.

--

George

Dec 4, 2012 at 10:26 AM

That is fine.