Restrict users from selecting past date (Date Validation)

Let’s learn how to restrict user form selecting past date. We can do this through JavaScript.

Below we have a Lead form, where we have a Target Date field. The need is to restrict user from saving the lead form having passed data on Target date field.

Lead Form

Below is the code which can we used:

(function () { }(window.BankNotes = window.BankNotes || {}));
(function (BankNotesFilter) {
/* Function ValidateTargetDate: This would trigger on OnChange event of Target Date field. Which would restrict user from selecting past date under Target Date field.*/
BankNotesFilter.ValidateTargetDate = function (executionContext) {
var formContext = executionContext.getFormContext();
var dateFieldVal = formContext.getAttribute("blog_targetdate").getValue(); // TargetDate Field
var today = new Date();
var todaydate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0);

if (dateFieldVal < todaydate) {
formContext.getControl("blog_targetdate").setNotification("Selected date should be greater or equal to today","101");
else {
// alert("Selected Target date greater than today");
}(window.BankNotes.BankNotesFilter = window.BankNotes.BankNotesFilter || {}));

The code restrict user from selecting past date on Target Date field.
If, user select past date under Target Date field then the field value will be cleared out showing notification(“Selected date should be greater or equal to today”) on the field.

Just, we need to call the above code on OnChange event of Target Date field:

Call the Function: BankNotes.BankNotesFilter.ValidateTargetDate

The value will be cleared out, on selection of past date

When a user select today’s or any future date, system will allow user to select the date.

User able to select any future/current date.

Hope this helps!

Filter LookUp: Set Regarding Lookup Entities

Let’s learn how to set entities under lookup field.

Let’s take an example of Regarding lookup of Task activity.

In the below image we can see that the regarding lookup contains multiple entities associated with it where a user can go and select any entity records.

Task Entity: Regarding lookup

To restrict “Regarding” lookup entities, we can use java script which would help us in populating only the needed entities.

(function () { }(window.LearningRefresh = window.LearningRefresh || {}));
(function (LearningRefreshFilter) {
LearningRefreshFilter.FilterRegarding = function (executionContext) {
var formContext = executionContext.getFormContext();
formContext.getControl("regardingobjectid").setEntityTypes(["contact", "incident", "account"]); //Regarding Lookup Field
}(window.LearningRefresh.LearningRefreshFilter = window.LearningRefresh.LearningRefreshFilter || {}));

We will need to call the java script “OnLoad” event of the Task activity main form.

The calling function should be LearningRefresh.LearningRefreshFilter.FilterRegarding

Save and Publish the changes.

Filter Regarding Lookup

Hope this helps!


As we all know that Microsoft Flow is also known as Power Automate.

So, it has some limitations as well. Like Request limit, Flow limits, etc. to know more about Limits and configuration in Power Automate,, click here.

Another important point about power automate is that it is priced based on the number of times the flow has been triggered.

So, today we will learn how can we restrict/filter our power automate trigger.

Here is the scenario, I have a custom entity(Blog Note) of activity type and I want my power automate to trigger on create of blog note record when it’s is created from the Contact entity.

Now, under the timeline section, I can see an extra activity entity named Blog Note under Account, Contact, Lead, and so on.

I have the power automate ready with me, which triggers whenever a record is created within the Blog Notes entity from any entity like account, contact, lead, and so on.

I want to restrict my flow run so that it triggers only when a user creates the blog notes from the Contact entity. If a blog notes is created from some other entity like account or lead then the flow should not trigger.

To handle this we need to go to the trigger step(Trigger on create of BlogNotes) setting.

Go to – trigger step Settings
Added the Trigger Condition

This is how we check if the regardingid is a contact entity then only the power automate trigger else it won’t.

I hope this helps!

Learning Power Automate – Check null for a variable

Today, we will learn how to check an empty value on a variable under Power Automate.

I had a requirement where I need to push my Lead record data from Dynamics CRM to another application.

To fulfill this requirement, I thought of going with power automate. Which would trigger whenever a record is created under the Lead entity and then push the data to another application.

Here I have a field Due Date which is an optional field on a form. So now it is a user who chooses to enter data or not.

I have a child flow where I need to pass the data of Due Data as well. Below is the JSON schema for Child Flow. We can see that the due date is of string type, therefore if we pass null value it would throw us an error: Invalid type. Expected String but got Null

JSON Schema

To handle this scenario, we can use an empty expression:

syntax: if (empty(duedate), ”, duedate)

expression used to check field(duedate) was empty:

if (empty(string(triggerOutputs() ? ['body/duedate'])), '', triggerOutputs() ? [' body/duedate'])

How the expression work is it checks whether the field is empty or not, which means if the value is null or empty then it returns true which will pass not null. This is accepted as a string. Else, if the field contains a value then it would pass the field value.

Hope this help!

Learning PowerAutomate – Get Option set label

Let’s learn how to get option set label, without query to string map table for retrieving the labels.

As, we know that querying to an entity option set field will give us the option set value not the label. So if we want to get the option set label against any value

Note*: we can use an expression to get option set labels.

I have an option set attribute named as Loan type, which is present on Lead entity.
Querying on Lead entity, for attribute Loan type. I get the option set value not the label.

Therefore, to get the label against the retrieved value. I went using replace expression:

replace(replace(replace(string(triggerOutputs() ? ['body/new_loantype']), '43260000', 'HomeLoan'), '43260001', 'BusinessLoan'), '43260002', 'PersonalLoan')

The expression replaces the option set value with the given label.
Example, whenever we get the loan type as ‘43260000’, using the expression I will get the result as “HomeLoan”.

Moving ahead, we can use the set variable step under our flow. Where we can use the expression based on the output we receive for the above steps.

Additionally on top of the above requirement handling process, I went into another scenario where the option set field was coming null.
Reason, the field was marked as optional field. So, now its a user choice to enter data for option set field or leave it as null.

So, whenever I was getting the null value for the option set field records, I was getting an error as: Invalid type. Expected String but got Null.

Therefore for handling the null value exception, I went using empty expression:

if(empty(string(triggerOutputs()?['body/new_loantype'])),'',replace(replace(replace(replace(string(triggerOutputs() ? ['body/ new_loantype']), '43260000', 'HomeLoan'), '43260001', 'BusinessLoan'), '43260002', 'PersonalLoan')

The above expression helps us in handling null value. When we are passing loan type value to another variable of string type or to a child flow when the expected schema is of type “string”.

I hope this helps anyone! 😊