Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

how to do date comparation in updateAccountJSON?

alc
Regular Contributor
Regular Contributor

Hello,

when we update an account, we need set its status to inactive if a user's last access date is earlier than 30 days. the user's customproperty33 (Just for example) has its last access date such as "20240416". How can I determine this date of this string is earlier than 30 days with one single line of code? and no new keyword to be used? looks the SimpleDateFormat with pattern "yyyyMMdd"" must be initialized with new keyword.

Is it possible to execute multiple javascript statements instead of single line of code in create/updateAccountJSON?

 

10 REPLIES 10

Raghu
All-Star
All-Star

@alc  Please find below sample:

${(user?.startdate.format('yyyy-MM-dd')<(Calendar.instance.format('yyyy-MM-dd')))?'true':'false'}


Thanks,
Raghu
If this reply answered your question, Please Accept As Solution and hit Kudos.

alc
Regular Contributor
Regular Contributor

Hello Raghu, Thanks for your help!

the startdate and Calendar does not have format method to call. is this javascript API different from Java API call?

Thanks

 

@alc  it will take current date format from Calendar Object .

use simple fomat object java

if (user?.startdate.format('yyyy-MM-dd') > new java.text.SimpleDateFormat('yyyy-MM-dd').format(new Date()))

 


Thanks,
Raghu
If this reply answered your question, Please Accept As Solution and hit Kudos.

alc
Regular Contributor
Regular Contributor

Hello Raghu, 

the "new" keyword is not allowed/recommended in Saviynt JSON setting.

try @alc 

${(Date.parse('dd-MM-yyyy', user?.customproperty1) > Date.now()) ? user?.customproperty1 : Calendar.getInstance().format('dd-MM-yyyy')}


Thanks,
Raghu
If this reply answered your question, Please Accept As Solution and hit Kudos.

rushikeshvartak
All-Star
All-Star

Option 1:

${Date.parse("dd-MM-yyyy", user.customproperty1)>(new Date())?user.customproperty1:(new Date().format("dd-MM-yyyy"));}

Option 2:

${Date.parse("dd-MM-yyyy", user.customproperty1)>(java.util.Calendar.instance.time)?user.customproperty1:(java.util.Calendar.instance.time.format("dd-MM-yyyy"));}

 


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

alc
Regular Contributor
Regular Contributor

Hello Rushikesh,

The 

java.util.Calendar.instance.time is not visible, it is not public field to access directly. Also I need compare with the date of 30 days ago, not today.

Please share conditions you tried as per your use case


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

alc
Regular Contributor
Regular Contributor

Hello Rushikesh,

This is what I have set:

${if(user?.customproperty1 != null && user.customproperty1.length() == 10 && new java.text.SimpleDateFormat('yyyy-MM-dd').parse(user.customproperty1).getTime() <= (Calendar.getInstance().getTimeInMillis() - (30*86400000))){'Invalid'}else{'Valid'}}

But the code reviewer said I cannot use new keyword to initialize java.text.SimpleDateFormat object.

Please help. the idea is to check if the specified user customproperty value is within 30 days of today or earlier than 30 days of today.

${if(user?.customproperty1 != null && user.customproperty1.length() == 10 && java.time.LocalDate.parse(user.customproperty1).isBefore(java.time.LocalDate.now().minusDays(30))){'Invalid'}else{'Valid'}}


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.