How to validate dates for dateperiod entity type

I am trying to design a standard HR assistant which will give user an option to apply leaves. Now for this I have Date Period Entity but I am not sure how to validate this.
Need to validate that From Date should be greater than the present date.
Need to validate that To Date should be greater than the From Date.

I have attached snaps for your reference.

I am new to this platform as well as JavaScript. Any leads would be appreciated.

@saswatdas4905

You are doing it in wrong, it won’t workout.

You need to define a script node to validate the From Date to Present date. Capture the date entered by user and then validate to present date using Script Node.

Hi Praveen,

Thanks for responding.

I followed the same but I am not able to write script for date period entity.
Hence I modified the designer flow and added two separate date entities for from date and to date and then added a script node to validate the difference as below snap:

image

image

However now I want to calculate the difference between these dates so that I can update balance and post it to a mock API.
But I am unable to do so.

Even I applied javascript function as below but it doesn’t work:

image

Ideally I wanted to store the balance and post it to Mock API so that leaves can be updated.
My Mock API looks like this
image

Any idea how I can accomplish this ?

Hi Praveen,

Thanks for responding.

I followed the same but I am not able to write script for date period entity.
Hence I modified the designer flow and added two separate date entities for from date and to date and then added a script node to validate the difference as below snap:

image

image

This works fine now
image

However now I want to calculate the difference between these dates so that I can update balance and post it to a mock API.
But I am unable to do so.

Even I applied javascript function as below but it doesn’t work:

image

Ideally I wanted to store the balance and post it to Mock API so that leaves can be updated.
My Mock API looks like this
image

Any idea how I can accomplish this ?

The date period entity returns a JSON object where the from and to dates are separate values and so they can be referenced in JS: context.entities.entityName.fromDate and context.entities.entityName.toDate

Ordinarily the platform will return the earliest date in fromDate and the latest date in toDate, so you don’t have to perform that check anyway.

You can also use entity rules to guide the entity on what dates are appropriate for this entity, see https://developer.kore.ai/docs/bots/how-tos/entity-rules/

Also note that script nodes support the Moment library through a koreUtil object, and I recommend using it for any kind of date and time handling. It is a lot simpler than the raw JS Date() object. See https://developer.kore.ai/docs/bots/advanced-topics/koreutil-libraries/#koreUtilmoment

Hi I am also getting same issue. Can you please help?

@suyogpathak2761998 Andy’s response in this thread should have helped. I see a similar post from you and the answer to that also is the same.