Question

I am trying to validate a SharePoint online task list column, in the way that the column "Assigned" (People column) must be populated for the user to be allowed to save with info in "Due date" (Date/time column).

That is - no due date without an assigned.

I looked at this thread, but didn't really understand how to write the formula for my needs. But I guess it's an easy task for experts :)

Could someone give me som help?

Was it helpful?

Solution

The OOB validate setting cannot validate the People picker, i recommend you insert a content editor web part in the new form or edit form page, then copy the JS code in it:

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script> 
<script type="text/javascript">
function PreSaveAction(){
    var assignTo = $("input[id^='AssignedTo'][id$='ClientPeoplePicker_HiddenInput']").val().length;
    var dueDate = $("input[id^='DueDate'][id$='$DateTimeFieldDate']").val().length;
    if(assignTo == 0 && dueDate != 0){ 
        alert("Please enter Assigned To for this user field");
        $("input.sp-peoplepicker-editorInput[id^='AssignedTo']").focus();        
        return false;
    }
    return true;
}
</script>​​

Then, when there is value in Due date but not in Assigned To column, you cannot save the item and get a alert.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top