comparing dates in groovy script

751 views
Skip to first unread message

Martin Schönbeck

unread,
Feb 24, 2021, 5:36:49 AM2/24/21
to iDempiere

Hi,

I tried to compare DateOrdered with login date in a groovy script (before complete validation). But I wasn't able to create a valid conversion of the login date. Can anyone give me a hint what's the right way?

I tried with 'new Date (G_Date)' and 'Date.parse ("yyyy-MM-dd", G_Date)' but either method are not known with this arguments or argument is illegal. I also tried with different hand coded date strings.

Regards,
Martin

Carlos Antonio Ruiz Gomez

unread,
Feb 24, 2021, 9:30:57 AM2/24/21
to idem...@googlegroups.com
Hi Martin,

Hard to help without the code.

I just had this idea, what if we open a wiki page "Rule Snippets" where
people can share rules that work, is just about adding the code and
explain what is that for.

I think many people do small things with rules, and would like to share,
but we don't have an "official" space (I have seen a few in these forums).

You can start that page with your rule and we'll find how to make it work.
BTW - what's the goal?

Regards,

Carlos Ruiz


El 24/2/21 a las 11:36, Martin Schönbeck escribió:

Martin Schönbeck

unread,
Feb 24, 2021, 10:11:32 AM2/24/21
to iDempiere
Hi Carlos,

Carlos Antonio Ruiz Gómez schrieb am Mittwoch, 24. Februar 2021 um 15:30:57 UTC+1:
Hi Martin,

Hard to help without the code.

Ok. That was the idea:

if (A_PO.getDateOrdered().before(new Date(G_Date).getTime() / 1000) && A_PO.getC_DocTypeTarget_ID() == 1000041)
   msg = "POS-Aufträge nicht für zurückliegende Daten";
else
  msg = "";

return msg;

I just had this idea, what if we open a wiki page "Rule Snippets" where
people can share rules that work, is just about adding the code and
explain what is that for.

That's what I was looking for. Of course I found some snippets in the documentation pages for scripts, but none helping here.  I probably could have done it with a SQL-rule, but now I want to get it done as script.
 
I think many people do small things with rules, and would like to share,
but we don't have an "official" space (I have seen a few in these forums).

You can start that page with your rule and we'll find how to make it work.
BTW - what's the goal?

Never provide wrong examples, they would spread before they could be corrected. ;-)

The goal was to hinder people to take an old offer, change it to POS-Order and complete it with an old date of an old period. Closing the old period for invoices helps, but it's to often forgotten to do it early in the morning of a new period.

Regards,
Martin

Carlos Antonio Ruiz Gomez

unread,
Feb 24, 2021, 11:24:02 AM2/24/21
to idem...@googlegroups.com
Hi Martin, that date is in format "yyyy-MM-dd HH:mm:ss"

I think is easier for you to use this to get the date already in the class you need:
Env.getContextAsDate(A_Ctx, "#Date")

Regards,

Carlos Ruiz


El 24/2/21 a las 16:11, Martin Schönbeck escribió:
--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/3f5466ef-3d92-4b97-8eef-de03925325e3n%40googlegroups.com.


Martin Schönbeck

unread,
Feb 24, 2021, 12:00:45 PM2/24/21
to iDempiere
Hi Carlos,

Carlos Antonio Ruiz Gómez schrieb am Mittwoch, 24. Februar 2021 um 17:24:02 UTC+1:
Hi Martin, that date is in format "yyyy-MM-dd HH:mm:ss"

I knew the format but didn't find a method to supply this format for the conversion.
 
I think is easier for you to use this to get the date already in the class you need:
Env.getContextAsDate(A_Ctx, "#Date")

That's even better. And together with a 'import org.compiere.util.Env;' it works.

Will prepare a snippet page.

Thanks,
Martin
Reply all
Reply to author
Forward
0 new messages