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)

Set field visibility based on owners business unit

(0) ShareShare
ReportReport
Posted on by

I figured out how to set the visibility of a field on the account form based on the owner of the account.  What I really want to do is set the visibility based on the business unit that the owner belongs to.

For example if account.owner.businessunit = BusinessUnitOne set the field visible.

Thanks,

Chris

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Set field visibility based on owners business unit

    Hi..

    you need to retrieve business unit of user using javascript and then you can hide / show attribute on form.

    To retrieve business unit for user using javascript

    [View:https://social.microsoft.com/Forums/en-US/0a648853-4cb6-432e-847c-88547c9ac24a/how-do-i-get-a-users-business-unit-crm-2011-javascript?forum=crm:0:0]

    [View:http://yeskanagaraj.blogspot.com/2013/01/get-current-user-business-unit-in-crm.html?_sm_au_=iVV2kFKMNK43bG0R:0:0]

    [View:http://mscrmblogger.com/2009/09/30/get-current-users-business-unit-for-hiding-fields/:0:0]

    Hope this will help.. 

  • Community Member Profile Picture
    on at
    RE: Set field visibility based on owners business unit

    Mahedeo,

    Thanks for responding to my question.

    This is close to what I am looking for and will help with some other things I am doing. I want to show the field based not on the logged in user but based on the account owner's business unit.

    Also I am using CRM 2015 online.  How do I use JavaScript in a business rule?  When I edit the form and click business  rule and create/edit a rule I get a GUI that lets me set conditions and pick fields from drop downs.  Is there an advanced editor that lets me use javascript and fetch?

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Set field visibility based on owners business unit

    Hi.. 

    You cannot use JavaScript in business unit.. you need to add JavaScript on form  Onload event

    and your javascript code will be look like 

    function ShowHideByOwnerBU()

    {

    // get owner Id

    var owner= Xrm.Page.getAttribute("ownerid").getValue();
    var ownername = owner[0].name;
    var ownerId= owner[0].id;

    // Get owner Business unit..

    // Based on owner BU show/hide fields.

    }

    To add javascript to form event.. 

    1. you need to create javascript web resource. 

    2. add this web resource to your entity form script libarary.

    3. then call function on form onload event.

    Here are some additional links might help you.. 

    [View:http://www.dynamicscrmpros.com/getting-started-with-javascript-form-scripting-for-microsoft-dynamics-crm-2011/:550:0]

    [View:https://msdn.microsoft.com/en-us/library/gg334481.aspx:550:0]

    [View:https://msdn.microsoft.com/en-us/library/gg309562.aspx:550:0]

    [View:https://msdn.microsoft.com/en-us/library/jj602964.aspx:550:0]

    Hope this will help.. 

  • Community Member Profile Picture
    on at
    RE: Set field visibility based on owners business unit

    hi, you can retrive Bs this way

    function GetUserBS()
    {
      var ContactID = Xrm.Page.context.getUserId();
        Cols = ["businessunitid"];
        var Retrieved = XrmServiceToolkit.Soap.Retrieve ("systemuser", ContactID, Cols );

        var UnitObj = Retrieved.attributes["businessunitid"];
        var UnitName = UnitObj.name

        return (UnitName);
    }

    then you can do whatever you want :D

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans