Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Set field visibility based on owners business unit

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee 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

  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 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
    Community Member Microsoft Employee 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?

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 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.. 

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans