You need to sign in to do that
Don't have an account?

button javascript to compare date
Hi,
I am trying to campare dates in a button javascript, but it doesn't work. Can anyone help me?
Code:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var tempdate = new Date("{!Case.Next_action_required_date__c}");
var agora = "{!NOW()}";
if( tempdate < agora)
{
alert("Please, inform the Next Action Required Date")
}
I am trying to campare dates in a button javascript, but it doesn't work. Can anyone help me?
Code:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var tempdate = new Date("{!Case.Next_action_required_date__c}");
var agora = "{!NOW()}";
if( tempdate < agora)
{
alert("Please, inform the Next Action Required Date")
}
I tried this code for Date time for filed
Next_action_required_date__c is date time type
I am getting all alert in case detail page when detail button will clicked
All Answers
The code is the cause of the issue, the javascript function Date accepts parameters in a different way.
Please follow the link (https://www.w3schools.com/js/js_dates.asp)to know more.
You would have to update that code accordingly.
If your requirement is not very complex i.e. Users all work in same timezone and all
try this bit of code
Hope it helps
RD
We are using date and date time filed .
first you will sure which kind off filed you are using
i have create alert for opportuntiy you can impolement your logic from this code
This is opp detail button.
todat date output from {!NOW}--> 10/4/2017 9:07 AM
close date output is: Wed Sep 27 2017 00:00:00 GMT+0530 (India Standard Time)
So please check data is returning date in date format ot datetime!
I hope is this helpful!
Thanks
varun
I tried your example, but i get the error: Invalid Date.
See my code:
var agora = "{!NOW()}";
var expirationDate = "{!Case.Next_action_required_date__c}";
var myDate = new Date(expirationDate);
myDate.setDate(myDate.getDate());
if( myDate < agora)
{
alert("Please, inform the Next Action Required Date" + myDate)
}
I have already tried your suggestion before, but didn't work.
Thank you!!
I fixed the code
You will get right result
Use the same code in button.
For your information i have created Next_action_required_date__c in my case object as Date type
If information is helpful select my answer as best answer!
Thanks
Varun
I have created the button with your code, but didn't work.
The field Next_action_required_date__c is a Date/Time format.
Thank you!
I tried this code for Date time for filed
Next_action_required_date__c is date time type
I am getting all alert in case detail page when detail button will clicked
1. Try putting an js alert with the expiration date. What do you get here?
2. Check the system timezone and the salesforce user timezone, just shooting in the dark here
RD
I have tested your code, but in the line "alert(myDate);" showed the error: Invalid Date.
Thanks.. I have inserted a verification in this field to verified if it has value.
Now is working with the code below:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var dealReg = new sforce.SObject("Case");
dealReg.id = "{!Case.Id}";
var expirationDate = "{!Case.Next_action_required_date__c}";
if(expirationDate != ""){
var nextAction = new Date(expirationDate).toISOString();
}
var startDate = "{!NOW()}";
var sDate = new Date(startDate).toISOString();
if(nextAction<sDate)
{
alert('Please, inform the Next Action Required Date');
}
Thank you Varun and RD@SF to help me!!