Welcome to the Sage CRM Support Group on Community Hub! Available 24/7, the forums are a great place to ask and answer product questions, as well as share tips and tricks with Sage peers, partners, and pros.
I need to validate an opportunity workflow rule based on the date the opportunity was created. For example the rule would only be valid if the creation date was before 03/10/2022.
Can anyone advise how/if this can be done?
0 Michele Gaw over 1 year agoNot exactly sure what you mean by "Validation". Therefore this might not be what you need.
However, if you want to show or hide a workflow step based on the creation date being before 03/10/2022, then you can do something like this.
Hope this helps!
0 joshSWR over 1 year ago in reply to Michele GawHi Michele - Sorry I probably wasn't clear in my post. By validation I meant the conditions on the rule, so exactly the kind of thing you mentioned, it's just specifically how to format the date check that I'm unclear about.
0 joshSWR over 1 year ago in reply to Michele GawI've just been testing something that I thought would work, but it's not behaving as expected.
var migrationDate = new Date('2022-10-02'); var createdDate = new Date(oppo_CreatedDate); if(createdDate > migrationDate) < Valid=false; >else if(oppo_type=='SO' && oppo_stage != 'IC') < Valid=true; >elseThis doesn't produce any errors, but the first condition also doesn't work as expected. It is returning a true value whether the creation date is greater than the specified date or not. Essentially if the creation date is greater than 2nd October 2022 it should return false.
Is there a formatting issue with the date that I'm not aware of?
0 Michele Gaw over 1 year ago in reply to joshSWRYes, it is an issue with the date. I find dates very tricky in javascript. Perhaps someone else can post an easier way to handle dates. :-)
I was jumping on the community to grab some other info. therefore, I will postback on how I would resolve the date. :-)
0 Michele Gaw over 1 year ago in reply to Michele GawOK. I took a look at your script. The field oppo_createddate contains date and time. I believe this is why it is not working for you.
The main take away is for the code you have above, you are comparing a date to a date/time so you may have to play with this script a bit. but I think it works. :-)
For what you are doing, I would try this. (Sorry I did not get a chance to test it.)
Add .setHours(0,0,0,0) to the end of your date variable. This will remove the time (hrs, min, sec, millsec)
Place the below line between lines 2 and 3 of your script above.
There are a lot of different ways to handle the date, so if the above does not work. There are another ways that will.
This is a helpful reference on dates.