Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 9TR3Kaymd86xI6pqkxHzNP
Power Apps - Microsoft Dataverse
Answered

Can Business Rule run after formload ?

Like (0) ShareShare
ReportReport
Posted on 9 Sep 2021 18:09:25 by 945

Hello everyone,

 

Can Business Rule applied or run after form load ? So I have a needs whereby, my field will only set to be mandatory, when the record is saved on the 1st time. For example : I'm creating new record, in one of the field lets say "Description", is not mandatory, user can save this new record. But after 1st saved, I want this Description to be mandatory. Problem is I have a Javascript to make an autosaved at first time the form load.

 

In my head, I would think like this :

  1. Had 1 business rule to check some field, I have 1 field which is an autonumber, which will have value when it's saved.
  2. So when this field is contain data, my business rule is Set Business Required this Description, if not contain data, don't make field Description as Business Required.

Is this make sense ?

Well, I tried like that, but it's not working, because it's looks like when it is saving (my java script to auto save running) then in that instance, the field "Description" is mandatory, so it is already return error.

 

Kindly advice whether it's possible to make the business rule run after form load, so my data will be saved first then displayed fully on the screen, then right after that my field become mandatory. So only at the 2nd time and after, when user click save, it will throw message that field is empty.

 

Thanks

  • Verified answer
    EricRegnier Profile Picture
    8,714 Most Valuable Professional on 13 Sep 2021 at 00:47:49
    Re: Can Business Rule run after formload ?

    Hi @Axal,

    It's not working because business rules run on load (no guarantee of the execution order) and after a field referenced in the business rule changes. So what @rampprakash is suggesting won't work.  If you absolutely need logic after a save event then you'll need JavaScript to register a function on post save event: https://docs.microsoft.com/powerapps/developer/model-driven-apps/clientapi/reference/events/postsave 
    Hope this helps!

  • Ram Prakash Profile Picture
    5,166 Super User 2025 Season 1 on 10 Sep 2021 at 05:02:37
    Re: Can Business Rule run after formload ?

    Hi @Axal,

     

    Please find the sample screenshot for business Rule for your reference.

     

    rampprakash_1-1631250526263.png

    Please mark as Answer if it is helpful and provide Kudos

     

    Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA

    Blog : https://microsoftcrmtechie.blogspot.com

     

  • Prakash4691 Profile Picture
    1,332 on 10 Sep 2021 at 01:51:39
    Re: Can Business Rule run after formload ?

    @Axal 

     

    I think you might be using 

    formContext.data.save(saveOptions), saveoption->savemode set to 70 to autosave using javascript.
     
    If you use above client API it runs asynchronously, that is why on onload your business rule triggers first and throwing an exception even before javascript executes.  
     
    To overcome the issue, deactivate business rule and handle everything using javascript.
     
    Including sample code below,
    function onload(executionContext) {
      var formContext = executionContext.getFormContext();
      if (formContext.ui.getFormType() == 2) {// check for form type it should run only on update and not on create
        var saveOptions = { saveMode: 70 };
        formContext.data.save(saveOptions).then(
          function (success) {
            formContext.getAttribute("cr5b9_jh").setRequiredLevel("required");// set required level
          },
          function (error) {
            console.log(error.message);
          }
        );
      }
    }
     
    If it answers your question, kindly give kudo and accept it as solution.
     
     
    Regards,
    Prakash
  • Axal Profile Picture
    945 on 10 Sep 2021 at 01:16:18
    Re: Can Business Rule run after formload ?

    Hi @rampprakash ,

     

    I'm sorry, what should I check on the entity ? and what is entity type to form ?

    Thanks

  • Ram Prakash Profile Picture
    5,166 Super User 2025 Season 1 on 10 Sep 2021 at 00:23:14
    Re: Can Business Rule run after formload ?

    Hi @Axal,

     

    Can you please remove all your existing logic and check the Entity type to form and tray again.

  • Axal Profile Picture
    945 on 09 Sep 2021 at 19:08:57
    Re: Can Business Rule run after formload ?

    Hi @rampprakash 

     

    Unfortunately, it is not working. With that rule, when my form load, it already give me error saying "Description" is empty.

     

    The form not shown first.

     

     

    Thanks,

     

  • Ram Prakash Profile Picture
    5,166 Super User 2025 Season 1 on 09 Sep 2021 at 18:56:34
    Re: Can Business Rule run after formload ?

    Hey @Axal,

     

    Please try this logic in Business Rule

     

    Condition :

     

    If CREATEDON contains Data

    Set Description field as Mandatory

    Else Description field not Mandatory

     

    Createdon Field will only store values if record gets created.

     

    Please mark as Answer if it is helpful and provide Kudos

     

    Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA

    Blog : https://microsoftcrmtechie.blogspot.com

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 15

#2
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

Overall leaderboard

Featured topics