web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Business Unit Id cannot be set to null error trying to create equipment record

(0) ShareShare
ReportReport
Posted on by 605

I was trying to create a facility/equipment with the following code, but i'm getting an error saying "business unit id cannot be set to NULL"

I have only one business Unit created in my crm 2016 Here is my code:

string fetchBU = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='businessunit'>
                                    <attribute name='name' />
                                    <attribute name='address1_telephone1' />
                                    <attribute name='websiteurl' />
                                    <attribute name='parentbusinessunitid' />
                                    <attribute name='businessunitid' />
                                    <order attribute='name' descending='false' />
                                  </entity>
                                </fetch>";

EntityCollection resultequipments = _orgService.RetrieveMultiple(new FetchExpression(fetchBU));

                if(resultequipments.Entities.Count > 0)
                {
                    Guid BuId;
                    BuId = (Guid)resultequipments.Entities[0]["businessunitid"];
                    Entity equipment = new Entity("equipment");
                    equipment["name"] = "test";
                    equipment["businessunitid"] = BuId;
                    _orgService.Create(equipment);
                    Console.WriteLine("Facility successfully created");
                }

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Rahul G J Profile Picture
    605 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    i am also facing difficulty in adding work hours for the created facility/equipment.

  • Rahul G J Profile Picture
    605 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    i am facing difficulty in adding work hours for the created facility/equipment.

  • Rahul G J Profile Picture
    605 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    Thanks a ton Gokhan Mentese for such a quick help!!  

  • Verified answer
    Gokhan Mentese Profile Picture
    145 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    If you have "timezonecode error" ,  add timezonecode property.

     equipment["timezonecode"] = 1;

  • Rahul G J Profile Picture
    605 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    Ya it worked!  Thanks a ton :)

    But business unit ID and timezone are autofilled. But still it expects us to explicitly give values ?

  • Verified answer
    Gokhan Mentese Profile Picture
    145 on at
    RE: Business Unit Id cannot be set to null error trying to create equipment record

    Hi 

    Try it.

    equipment["businessunitid"]= new EntityReference("businessunit",BuId);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans