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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Issues with business r...
Power Apps
Unanswered

Issues with business rule in Dataverse. It's not working when I want to update multiple records

(0) ShareShare
ReportReport
Posted on by 27
Hello Folks, 
 
Seeking your help regarding one of the business rules I applied in my Dataverse table. It's only working when I update a single record in the form, however doesn't work when I want to update multiple records. 
 
Requirement: if user selects 'Remove' value in Keep/remove column, show additional drop-down field Reason for removal on the form and make it mandatory/business required. 
 
This works perfectly fine, when a single record is updated. Reason for removal shows only when Remove value is selected. But how can I make this working in bulk edits, when I want to update two or more records via form? 
Below screenshot shows that everything looks alright for single record update. 
Below screenshots show that the rule isn't working when multiple records are selected. 
When I select 'Remove' value in Keep/remove drop-down, Reason for removal field doesn't show up but when I try to save the records, there's an error message. So it looks like the system recognizes the business rule, but it doesn't display Reason for removal field when I want to update more than one record on the form. 
My business rule scope is set to Entity, I also switched it to All Forms, but it didn't help. 
 
Below you can also see the screenshot of the business rule. 
 
I have the same question (0)
  • Richard_S Profile Picture
    34 on at
    Bulk edit is a bit tricky at times in my experience.. Could the case that business rules don't apply to bulk edit forms.
     
    I would suggest implementing a javascript with the same logic and check on the formType 6 (bulk edit)
  • PP-23070628-0 Profile Picture
    27 on at
    @Richard_S thanks for your message. Do you know if there's any other way to do it? I'm not very familiar with building javascript logic. 
  • PP-23070628-0 Profile Picture
    27 on at
    Or maybe could you share some documentation how can this be applied in javascript?
  • Richard_S Profile Picture
    34 on at
    Hi,
     
    If I understood correctly you want show the field 'Reason for Removal' if Keep/Remove is set to 'Remove'. Here is a JavaScript that should work:
     
     

    function Onload(executionContext) {

        //Execution Context needs to be passed as first parameter in form event handler

     

        try {

            var functionName = Onload.name;

            let formContext = executionContext.getFormContext();

     

            let formType = formContext.ui.getFormType();

            switch (formType) {

                case 6:

                    if (formContext.getAttribute("$Keep/remove").getValue() == "$Remove") {

     

                        formContext.getControl("$ReasonForRemoval").setVisible(true)

     

                        formContext.getAttribute("$ReasonForRemoval").setRequiredLevel("required")

                    }

                    break;

                default:

                    break;

            }

        }

        catch (e) {

     

            //Error Message, not necessary for the logic to work

            let alertStrings = { confirmButtonLabel: 'OK', text: "Function name: " + functionName + "\nMessage: " + e.message, title: "JavaScript erro" };

            let alertOptions = { height: 180, width: 260 };

     

            Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(

                function (success) {

                    // perform operations on alert dialog close

     

                },

                function (error) {

                    console.log(error.message);

                    // handle error conditions

                }

            );

        }

    }

     

    1. You will need to replace the following:

    - $Keep/remove: Is the logical name of your corresponding field

    - $Remove: Is the value of the optionset when it's set to 'Remove' (e.g. 100000001)

    -$ResaonForRemoval: Is the logical name of your field which should be visible and required.

     

    2. You will need to create a Webresource (JScript) and paste/Upload the code there

    Create web resources in Dynamics 365 Customer Engagement (on-premises) | Microsoft Learn

    3. You will need to register the Webresource in the OnLoad Handler of your form (Main form)

    Walkthrough: Write your first client script in model-driven apps - Power Apps | Microsoft Learn

     

    If you have problems/questions, let me know.

  • PP-23070628-0 Profile Picture
    27 on at
    @Richard_S thanks again for providing these instructions. I went ahead and created a web-resource, however I don't know what function should be entered in the OnLoad handler in my form. In your javascript I saw you set a variable Onload.name, but I think I'm entering this in a wrong way. Please have a look at the below screenshots (On Load handler and error in model-driven Power Apps).  I also attached the web resource js code.
     
     
    function Onload(executionContext) {
    
        //Execution Context needs to be passed as first parameter in form event handler
    
     
    
        try {
    
            var functionName = Onload.name;
    
            let formContext = executionContext.getFormContext();
    
     
    
            let formType = formContext.ui.getFormType();
    
            switch (formType) {
    
                case 6:
    
                    if (formContext.getAttribute("cr6bb_keepremove").getValue() == "431800001") {
    
     
    
                        formContext.getControl("cr0e5_managercommentsdropdown").setVisible(true)
    
     
    
                        formContext.getAttribute("$ReasonForRemoval").setRequiredLevel("required")
    
                    }
    
                    break;
    
                default:
    
                    break;
    
            }
    
        }
    
        catch (e) {
    
     
    
            //Error Message, not necessary for the logic to work
    
            let alertStrings = { confirmButtonLabel: 'OK', text: "Function name: " + functionName + "\nMessage: " + e.message, title: "JavaScript erro" };
    
            let alertOptions = { height: 180, width: 260 };
    
     
    
            Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
    
                function (success) {
    
                    // perform operations on alert dialog close
    
     
    
                },
    
                function (error) {
    
                    console.log(error.message);
    
                    // handle error conditions
    
                }
    
            );
    
        }
    
    }
     
  • Richard_S Profile Picture
    34 on at
    Hi,
     
    just write „Onload“ in the function box. This has to be the same as the text after „function“ in the code. You can name this whatever you like. For example, if the function in the webressource code would start with function xyz{}, you would have to fill in xyz. 
     
    var functionName is just a variable I generally use to reference in the catch block later.. this is for error handling.
     
    If you change your function name, you would have to change this as well
     
    e.g var functionName = xyz.name
     
    or you can just delete the variable declaration. But then you would have to delete it from the alertStrings as well. 
     
    Will Post you the script without this later on.
     
     
  • PP-23070628-0 Profile Picture
    27 on at
    @Richard_S Richard_S - I changed it to OnLoad in the function box, but still it doesn't work. I also saw I had one typo in the javascript, which I now updated. I didn't update $ReasonForRemoval field with Dataverse logical name, but now the web resource is updated and republished. I attached the most up-to-date script. 
     
    Not sure it this helps, but the script error only pops up when I want to edit one record (I tried with having my business rule turned on and off). When I want to edit multiple records, the error doesn't show up, however the conditional behavior doesn't work. 
     
     
     
     
    Conditional behav...

    Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

  • PP-23070628-0 Profile Picture
    27 on at
     Richard_S - small update. I don't receive the script error anymore. Single record update works with the applied business rule, however nothing happens when I select 'Remove' value in Keep/remove field when I do the bulk edits. Reason for removal field doesn't show up. No idea why it's not working. Below you can see a screenshot of my form, where Reason for Removal field is hidden by default. 
    Conditional behav...

    Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

  • Richard_S Profile Picture
    34 on at
    Hi,
     
    I just noticed, that it seems you are showing your 'Manger Comments' field which is visible either way?
     
     
    "cr0e5_managercommentsdropdown" should be the logical name of your field 'Resons for Removal' or am I getting it wrong?
     
    Regards
  • PP-23070628-0 Profile Picture
    27 on at
    Richard_S  good question. When I first created this columm I named it ManagerCommentsDropDown, just for testing purposes. Then I changed it's display name to Reason for Removal, but the logical name stayed the way it was created. So summing up, I'm showing 'Reason for removal' field which logical name is as the one in your screenshot. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard