2

I've sharepoint OOTB list, where I want to validate a date column based on other date column. For EX: consider two columns like Date1 & Date2. Where Date2 is calculated based on other columns. And I need following validation done at Date1 column.

Date1>Date2

I've tried with column validation, but in SharePoint there is some restriction that I can't use another column on column validation. Pls help to achieve it.

Thanks,

Arun

0

Here are the steps to set up your validation :

  1. Navigate to your List Settings and Select ‘Validation settings’ under the General Settings heading:

enter image description here

  1. This will take you to your Validation Settings page where you can enter your Formula and a message to be displayed to your user if the validation check fails. Enter your formula in the Formula column and in the User Message column enter the message to be displayed to the user if the validation fails. enter image description here
  2. Select Save and that’s all there is to it.
  • 3
    The key sentence from OPs question is Where Date2 is calculated based on other columns, that means Date2 is not available for Validation because it is calculated when the Item is saved. – Danny '365CSI' Engelman Feb 15 '16 at 10:17
  • Oh yes...I missed that – P S Feb 15 '16 at 10:34
0

You can use multiple columns in form validation, as described by @PS. There are some restrictions with using calculated columns.

Let's say Date2 is calculated column with formula:

=Today()

The following validation formula is incorrect, because it uses calculated column:

=[Date1]>[Date2]

What you can do, is copy Date2 formula into the validation. This one works:

=[Date1]>Today()

I could not find any reliable source to confirm it, but from what I've seen, not every calculated column is forbidden. If you set up Date2 as:

=Date(2016, 02, 15)

You'll be able to use it in validation.

  • The date2 column is calculated based on other 2 date columns. Consider Date3 & Date4 columns have manually entered date values. So the Date2 = Date3+Date4. Now I need to validate for Date1 like Date1>Date2 – Arun Feb 15 '16 at 15:05
0

There is workaround where you can do the validation using jquery, where you can write down all the logic in SharePoint PreSaveItem() function

Sample Snippet:

 function PreSaveItem() {
       var date1=$(["id ^= date1field"]).val();
       var date3= $(["id ^= date3field"]).val();
       var date4=$(["id ^= date4field"]).val();
       var date2=date3+date4;
      if(date1 > date2){
          return true;
        }
   else{
     alert('error message');
     return false;
     }

    }

Note :Date field conversion should be done for comparision

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.