Date Validation

SUGGESTED

Hi

we have a field on the opportunity screen (proposed date), the client wants to prevent users from entering dates in the past

is there any code i can use for this please?

Many Thanks

Sufyan

Parents
  • 0

    Hi Vega

    thanks for this, do you have any examples of code that i can use to achieve this?

    any help is much appreciated

  • 0 in reply to SIQ

    Hi Matthew

    thanks for this, ive tried by replacing the oppo_targetclose with new date() but i get a error saying:

    lead_opened jscript error: Object doesn't support this property or method Line: 12 Char: 0

    this is the code ive entered in the validation script against the lead_opened field

    var aNextFollowUp = new Array();
    var InputNextFollowUp = Values('lead_opened');
    var aNextFollowUp = InputNextFollowUp.split("/");
    var DateNextFollowUp='';
    if(aNextFollowUp.length==3)
    {
    DateNextFollowUp = new Date(aNextFollowUp[2], aNextFollowUp[1]-1, aNextFollowUp[0]);
    }
    var aTargetClose = new Array();
    var InputTargetClose = new Date();
    var aTargetClose = InputTargetClose.split("/");
    var DateTargetClose='';
    if(aTargetClose.length==3)
    {
    DateTargetClose = new Date(aTargetClose[2], aTargetClose[1]-1, aTargetClose[0]);
    }
    if (DateNextFollowUp!='' && DateTargetClose!=''){
    if (DateTargetClose > DateNextFollowUp)
    {
    Valid = false;
    ErrorStr = 'Cannot enter date in the past';
    }
    }

    ive tried setting so instead of using new date() i use lead_createddate as would work aswell in this case - but it only works if the lead_createddate field is set as an editable field - if i set the lead_createddate field as readonly the validation script doesnt fire

    any ideas?

  • 0 in reply to SIQ
    SUGGESTED

    The problem you'll have is the user preferences setting because if the user has their date format preference set to something that you're not expecting you'll get errors. I've had a look at this but it started to get complicated due to the user preference setting. Ignoring it might be easy but any validate script shouldn't ignore it.

    This works in validate scripts to get the preference: CRM.UserOption('NSet_UserDateFormat'); Then you'll need to get the two dates without the time element and then you can compare them.

Reply
  • 0 in reply to SIQ
    SUGGESTED

    The problem you'll have is the user preferences setting because if the user has their date format preference set to something that you're not expecting you'll get errors. I've had a look at this but it started to get complicated due to the user preference setting. Ignoring it might be easy but any validate script shouldn't ignore it.

    This works in validate scripts to get the preference: CRM.UserOption('NSet_UserDateFormat'); Then you'll need to get the two dates without the time element and then you can compare them.

Children
No Data