Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

Business rules

  • 1.  Business rules

    GOLD CONTRIBUTOR
    Posted Dec 26, 2018 08:53 AM
    ​Hello Team,

    We would like a notification to be shown to the user when he enters all the fields on the form . This notification would say "Please save record to enter more details. We have been able to achieve this using Business rules

    form
    It works all fine . We wanted to know if there would be a way to save the record when we click on "Apply" . As we are building a new system we would like to avoid any code and we wanted to understand if we can do the same using business rules.


    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------
    CRMUG Summit - Post


  • 2.  RE: Business rules

    TOP CONTRIBUTOR
    Posted Dec 26, 2018 01:54 PM
    That is not possible through using only business rules. That would require some JavaScript code.

    ------------------------------
    Nelson Johnson
    Solution Architect
    BroadPoint Technologies, LLC
    Bethesda MD
    ------------------------------

    CRMUG Summit - Post


  • 3.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Dec 27, 2018 11:37 AM
    ​Hello Nelson,

    Thank you for your reply . I wanted to just check if there would be a way in which we could avoid code usage .

    I was also thinking to check if there would be a way to hide the "apply" button from the notification ? Or maybe there could be way in which I can just say "Save the record first to enable the sub grid" -- similar to the message that Timeline displays in general under UCI when we go in to create a new record.

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 4.  RE: Business rules

    TOP CONTRIBUTOR
    Posted Dec 28, 2018 03:04 PM
    I have never seen an "apply" button in the new UI. what kind of field is that?

    ------------------------------
    Nelson Johnson
    Solution Architect
    BroadPoint Technologies, LLC
    Bethesda MD
    ------------------------------

    CRMUG Summit - Post


  • 5.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Dec 31, 2018 09:31 AM

    Second that. Where did the Apply button come from?

    Note, the code to save a record would be very short. Something like this would do. 

    mySaveFunction(){
        formContext.data.entity.save();
    }


    MSFT Documentation is here:
    save (Client API reference) in Dynamics 365 for Customer Engagement





    ------------------------------
    Ryan Perry
    Auric Solar
    ------------------------------

    CRMUG Summit - Post


  • 6.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 02, 2019 08:33 AM
    ​Hello Ryan,

    Thank you for your reply. We get the "Apply " button when we use a recommendation in a business rule . The recommendation asks us for an action to be added with it. This action is mandatory to complete the business rule. so  once when a business rule runs successfully the action gets applied using the "Apply" button.

    Apply Button

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 7.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 02, 2019 08:36 AM
    Thank you Ryan for your reply. I am also guessing that we will need to attach this code to the "Apply button" and to do the same will need to use the ribbon workbench. Pleae guide me if my understanding is incorrect .

    Once again many thanks for your reply :-)​

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 8.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 02, 2019 10:09 AM
    Edited by Ryan Perry Jan 02, 2019 10:10 AM
    Hi Bhartendu,

    You can just connect it to the field OnChange event.

    Open the form editor > Selected field's Field Properties > Events tab:
    Event Handlers in Form Editor
    In the Form Libraries is where you put the actual code. These are saved as web resources. Note: You will need to publish all to ensure they publish.  They do NOT automatically publish when you publish the form as they are a separate system component.

    Once you've added a javacript web resource in the Form Libraries section, you can add the event handler, as shown above. This will execute the code whenever the specified event occurs.  In the case of the suggestion, if the user clicks "Apply" it is effectively allowing the user to change the field value, which will trigger the event.  You may even be able to just get rid of the recommendation as it will save automatically.

    Also, under the pre-version 9 model,  the code would have just used Xrm.Page to reference the form for executing the save function. You didn't need to pass the execution context to it.   Under the new model, this has changed a bit and I over-simplified a bit based on the old model. Under the new model, you now should pass the execution context to your function and get the formcontext from that. Here's how:

    You should pass the execution context.
    The code receives the context and references it:
    //New Code for V9
    function AutoSave (executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.data.entity.save();
    }
    
    
    //Old code. Still works, but deprecated.
    function AutoSave() {
        Xrm.Page.data.entity.save();
    }

    Hope this helps.


    ------------------------------
    Ryan Perry
    Auric Solar
    ------------------------------

    CRMUG Summit - Post


  • 9.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 07, 2019 11:43 AM
    ​Hello Ryan,

    Thank you for your detailed reply. I will be working through the same . :-).
    Really appreciate you taking the time to get all the details .

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 10.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 07, 2019 05:35 PM
    You're very welcome. Good luck.

    ------------------------------
    Ryan Perry
    Business Systems Analyst
    Auric Energy
    ------------------------------

    CRMUG Summit - Post


  • 11.  RE: Business rules

    TOP CONTRIBUTOR
    Posted Jan 02, 2019 11:16 AM
    I am not aware of anything in ribbon workbench that would allow you to add the code to that Apply button. If you are willing to discuss using code, then you have some better options.

    As I understand your original goal is to save the record after the user has filled in the required fields. You have to decide how much you want to commit to code or use business rules. For example, you could put some logic in business rules, and a tiny bit of JS code which would limit how much code you have to maintain. To illustrate, Let's say you have 3 fields today that are required, and you think there might be more later. You could make a business rule that checks all the fields, and when they are populated, it can set a value of a new hidden custom string field (lets call it Form Completed) to a value of "Yes". Then you just need a JavaScript web resource that is loaded with the form and the OnChange event would call the 1 line of code that Ryan proposed above. Since the field is hidden, the only way it can be changed is when all the business rule conditions have been met, which would then save your form.

    ------------------------------
    Nelson Johnson
    Solution Architect
    BroadPoint Technologies, LLC
    Bethesda MD
    ------------------------------

    CRMUG Summit - Post


  • 12.  RE: Business rules

    GOLD CONTRIBUTOR
    Posted Jan 07, 2019 11:52 AM
    ​Hello Nelson,

    Thank you for your reply .
    I need the recommendation to be show as it is the desired functionality I wanted to achieve . I have created a hidden field and placed it on the form . Now when I click the apply button the field gets updated with a random value . I will now add the javascript code which will trigger on the update of the hidden field value.

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 13.  RE: Business rules

    TOP CONTRIBUTOR
    Posted Jan 07, 2019 12:01 PM
    Ryan Perry gave the exact steps you should follow (above) - just edit the new hidden field Event  OnChange and create the code he gave you.

    ------------------------------
    Nelson Johnson
    Solution Architect
    BroadPoint Technologies, LLC
    Bethesda MD
    ------------------------------

    CRMUG Summit - Post


If you've found this thread useful, dive deeper into User Group community content by role