0

I want to do an IF statement and if its true then I want another column to be set.. I am using list validation on a Sharepoint list:

=IF([Master vs Copy])="Master",([Duplicate Rationale])="None"), TRUE) 

So the column called 'Duplicate Rationale' is a choice column and I want to set it to value None (which is in the columns).

Any help would be brilliant as I don't know how to set a column in list validation.

1

We can use jQuery code to achieve it.

Example:

I create a custom list with the choice columns "Master vs Copy" and "Duplicate Rationale".

Then add the code below into script editor web part in the newform.aspx page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function PreSaveItem(){ 
    var masterVsCopy=$("select[title='Master vs Copy']").val();
    var duplicateField=$("select[title='Duplicate Rationale']");
    if(masterVsCopy == "Master"){
        $("select[title='Duplicate Rationale']").val("None");
    }
    if(masterVsCopy=="Copy"&&(duplicateField.val()==""||duplicateField.val()=="None")){
        alert("Please select a value of Duplicate Rationale field.");
        return false;
    }
    return true;
}
</script>

enter image description here

  • perfect but not possible with Sharepoint online is it ?? – user3437628 Mar 1 at 12:47
  • SharePoint Online classic also works, in modern list, we can't add custom JavaScript in list form page. – LZ_MSFT Mar 4 at 1:10
0

You cannot set with Column Validation another column. Just Create Duplicate Rationale like Calculated column and here fill this expression:

=IF([Master vs Copy])="Master","None", "")
0

No.

You cannot set the list column in validation formula.

Solution:

  1. Create a calculated column with name Duplicate Rationale.
  2. Use below formula for your calculated field:

    =IF([Master vs Copy])="Master","None", "OtherValue")

Reference:

  1. Calculated Field Formulas.
  2. How to create calculated columns.

Is there any other reason for using choice column?

  • because if Master vs Copy is equal to copy then Duplicate Rational has to have content. – user3437628 Feb 27 at 14:44
  • What is the type of master vs copy? – Ganesh Sanap Feb 27 at 14:51

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.