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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Business rule in dynamics 365

(0) ShareShare
ReportReport
Posted on by 1,085

Hello Community Experts,

I have created a business rule and the business rule should fire only for few users not t all

Is it possible to make it work like that?

Kindly guide,

Best Regards,

Sumaira Noor

I have the same question (0)
  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Sumaira,

    Business Rule could not only show to special users but you could try another way.

    As we know, different forms have different BR,  and we could enable/disable security roles for forms. So for example you want to enable a BR in account form only for sales person, so you could do the following steps.

    1.Go to Settings->Customizations->Customize the System -> Account.

    And select a form and click on "Enable Security Roles".

    pastedimage1587024746352v1.png

    2.Select "Sales person" only in the list.

    pastedimage1587024789261v2.png

    3.Create the BR in this form and then only sales person will be available for this BR.

    Regards,

    Leo

  • Sumaira Noor Profile Picture
    1,085 on at

    Thanks a lot for the response Leo

    but i want to make the lead form available for all 6 users

    among 6 only for 3 the business rule should be applied

    i.e lead older than 3 months should be available to these 3 but the leads created from past 3 months should not be available

    with the help of this tread, i was able to create a business rule but i want it to be available only for 3 users

    community.dynamics.com/.../read-only-field-in-dynamics-365

    Kindly guide

    Best Regards,

    Sumaira Noor

  • meelamri Profile Picture
    13,218 User Group Leader on at

    Hi Sumaira Noor,

    I add a simple solution to your issue in community.dynamics.com/.../read-only-field-in-dynamics-365

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Sumaira,

    Thanks for your details.

    Since so, I recommend you to use JS code instead.

    We could add custom JS code in lead form onload event.

    Please refer to the below steps.

    1.The first thing we should do is get the datediff between now and createdon.

    //get createdon time of the lead record
        var createdon=formContext.getAttribute("createdon").getValue();
        //get current datetime
        var currentDate=new Date();

    2.Second thing is get the current user name to confirm if we should run the business rule.

    //get current username
        var userSettings = Xrm.Utility.getGlobalContext().userSettings;
        var username=userSettings.userName;

    3.Then we could add custom JS code to control the fields as your requirement, like hide/disable/readonly/set value....

    Here's the complete code.

    function runRule(executionContext){
        var formContext=executionContext.getFormContext();
        //get createdon time of the lead record
        var createdon=formContext.getAttribute("createdon").getValue();
        //get current datetime
        var currentDate=new Date();
        //get the datediff between times
        var days=getDateDiff(createdon,currentDate);
        //get months
        var months=days/30;
        //get current username
        var userSettings = Xrm.Utility.getGlobalContext().userSettings;
        var username=userSettings.userName;
        //start judge
        if(months>3){
            if(username=="A"||username=="B"||username=="C"){
                //set the rules here with JS code like hide/disable/setvalue....
            }
        }
    }
    
    
    function getDateDiff(sDate1,sDate2){
        function daysBetween(sDate1, sDate2) {
            var time1 = Date.parse(new Date(sDate1));
            var time2 = Date.parse(new Date(sDate2));
            var nDays = Math.abs(parseInt((time2 - time1) / 1000 / 3600 / 24));
            return nDays;
        }
    }

    You could set your rules through JS code as what you did in business rule, you could refer to this doc for more actions JS could do to control the attributes. You could also tell us your rules and we could provide sample code to you as well.

    4.Then we should add this JS function to lead form onload event.

    Go to form editor->form properties.

    Add the whole JS code as a web resource into D365 by clicking the add button in "Form Libraries".

    Add the JS fucntion "runRule" into form onload event bu clicking the add button in "Event Handlers".

    pastedimage1587088349311v1.png

    When adding functions, remember to select "Pass execution context as first parameter".

    pastedimage1587088444037v2.png

    Hope it helps.

    Best Regards,

    Leo

  • Sumaira Noor Profile Picture
    1,085 on at

    The above code helped me a lot in completing my requirement, i learned new things while completing it

    Thanks a lot Leo

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Sumaira,

    I'm so glad to hear that, that's my pleasure :)

    Hoping you enjoy D365.

    Best Regards,

    Leo

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 177

#2
ManoVerse Profile Picture

ManoVerse 54 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans