dynamics-crmconditional-statementsmicrosoft-dynamicsbusiness-rulesdynamic-values

Microsoft Dynamics need to specify today's date as a condition for a business rule


I am creating a business rule that changes the contents of the description depending on the time of day that the email is created.

enter image description here

Ideally, I would like to specify the value of date to be today's date, as the date is constantly changing. However, I need the time (12:00pm) to stay the same.

Is there a way of doing this?


Solution

  • You cannot set today's date with a business rule.

    Instead, you can use JavaScript to compare the time part of CreatedOn with 12:00, which could be done as follows:

    function onLoad() {
        var createdOn = Xrm.Page.getAttribute("createdon").getValue();
        var noon = new Date(createdOn.getTime());
        noon.setHours(12, 0, 0);
    
        Xrm.Page.getAttribute("description").setValue(createdOn < noon ? "Good Morning" : "It's after noon!");
    }