Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)
Suggested answer

How to find the owning business unit's field id of an case during the onload event using in javascript

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a need to determine the owningbusinessunitid of an case during the onload event of the case form. Does anybody know of a way to find this in javascript. 

The owningbusinessunit is a "No Display" field in the attributes list of the case. so therefore can not be added to a form. 

I do not need to change the value in any way, just need to execute some conditional logic based on the value.

and also what was the owning business unit id. 

Regards,

Eliyas

Categories:
  • Suggested answer
    necsa Profile Picture
    necsa 3,455 on at
    RE: How to find the owning business unit's field id of an case during the onload event using in javascript

    Hi EliyasH,

    you can use CRM Rest Builder tool to get value of owning business unit value.

    forexample as jquery,

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/incidents()?$select=_owningbusinessunit_value",
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
            XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
        },
        async: true,
        success: function (data, textStatus, xhr) {
            var result = data;
            var _owningbusinessunit_value = result["_owningbusinessunit_value"];
            var _owningbusinessunit_value_formatted = result["_owningbusinessunit_value@OData.Community.Display.V1.FormattedValue"];
        },
        error: function (xhr, textStatus, errorThrown) {
            alert(textStatus + " " + errorThrown);
        }
    });

    to download

    https://crmrestbuilder.codeplex.com/

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to find the owning business unit's field id of an case during the onload event using in javascript

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/contactSet?$select=OwningBusinessUnit", true);

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.onreadystatechange = function () {

       if (this.readyState === 4) {

           this.onreadystatechange = null;

           if (this.status === 200) {

               var returned = JSON.parse(this.responseText).d;

               var results = returned.results;

               for (var i = 0; i < results.length; i++) {

                    var owningBusinessUnit = results[i].OwningBusinessUnit;

               }

           }

           else {

               alert(this.statusText);

           }

       }

    };

    req.send();

    output

    {

    OwningBusinessUnit:{

    Id:"000043cf-0caf-0000-0000-0000000c6c10",

    LogicalName:"businessunit",

    Name: null

    }

    },

    If my response is helps you, please mark as "Verified"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,876 Super User

#2
Ludwig Reinhard Profile Picture

Ludwig Reinhard Microsoft Employee

#3
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans