DFFS rule/required field based on items in child list

Forums vLooup for SharePoint DFFS rule/required field based on items in child list

This topic contains 2 replies, has 2 voices, and was last updated by  Alexander Bautz 2 months ago.

  • Author
    Posts
  • #14137

    AdamP
    Participant

    I’ve had a request to improve a form so that it can only be saved if an entry has been created in a vLookup child list. Is there any functionality that would allow this to easily be achieved?
    It doesn’t matter how many entries there are as long as there are more than zero – essentially making the vLookup column into a required field on the parent form.

    Thanks

    Adam

  • #14190

    Alexander Bautz
    Keymaster

    Hi,
    You can use the “spjs.vLookup.dataObj” to check if there are any child items. Use the function like this:
    I have updated the code snippet in the below comment.
    Change “The_name_or_your_vLookupField” to match your vLookup field.

    Alexander

  • #21861

    Alexander Bautz
    Keymaster

    I’m editing this old post because there was an error in the original comment.

    function dffs_PreSaveAction(){
        var hasChildren = false;
        if(spjs.vLookup.dataObj["The_name_or_your_vLookupField"] !== undefined && spjs.vLookup.dataObj["The_name_or_your_vLookupField"][spjs.dffs.data.thisItemID] !== undefined && spjs.vLookup.dataObj["The_name_or_your_vLookupField"][spjs.dffs.data.thisItemID].count > 0){
            hasChildren = true;
        }
        if(!hasChildren){
            alert("You must add a child item before you can save this item");
            return false;
        }
        return true;   
    }

    Alexander

You must be logged in to reply to this topic.