4 Replies Latest reply on Mar 15, 2016 11:52 AM by mikebeargie

    Validation on related field

    AdamSnyder_1

      I have a product table with a list of related vendors.

       

      I want to make vendor cost field in the related table a required value, but when I set field validation to 'not empty' and try to leave the layout, it doesn't trigger the validation on the related record.

       

      How do I force a user to enter a value into a field in a related record?

       

      Edit:  I just added a script trigger on field exit to check if the field is empty.  This works since after adding the vendor, the user in the cost field.  If I had more than 1 required field, this method wouldn't work though.

        • 1. Re: Validation on related field
          mikebeargie

          Ideally you would put the validation in the products table itself, so that would force the product to have that data at the time of entry. Validation rules aren't really ideal for walking across relationships, so using a trigger to check is a reasonable solution.

           

          You may want to make it an onObjectModify trigger so that user is proactively warned when a product without a price is selected. Rather than when they later try and save the record.

          • 2. Re: Validation on related field
            mikebeargie

            Actually reading into it further, vendor cost IS in products right? It doesn't belong as a field in vendors, as a vendor should have the ability to have their price for each product. Your description wasn't very clear as to which table that vendor price lived in.

            • 3. Re: Validation on related field
              AdamSnyder_1

              Thanks for the reply.

              Sorry I wasn't clear about the schema.

               

              It's a many to many relationship.  There are 3 tables.  Products, Vendors, and ProductVendors.

               

              A product can be purchased from many vendors, and vendor can have many products.

               

              Each vendor will have unique product cost, so the cost and item number are stored in the productVendors join table.

              • 4. Re: Validation on related field
                mikebeargie

                Then yes, the ProductVendors join table should be where you validate for the missing price.