Validation by checking a particular field on each row versus the last row

Having some trouble finishing up a particular app for our users because of one validation. I have built a way for the user to merge multiple line items at a time, but currently they are able to merge different types of parts together, which is not something we want them to be able to do. We want the new merged item to be only one part. This information is taken by adopting the chosen rows into a new model. Tried to do a validation with branching action framework, but it wasn’t looping through each row in the model. Working on putting together a snippet to handle this, but so far it’s not working right.

Previously, I had the problem that some of my variables were coming up as undefined. I think I’ve gotten around that problem for the most part.

Any suggestions would be welcome.

var params = arguments[0], $ = skuid.$; // variables var NumbersToMerge = skuid.model.getModel('NumbersToMerge'); var SamePart = true; //Check each row and compare part field $.each(NumbersToMerge, function(i, row){ //if not the same, change SamePart to false if(this.Part != NumbersToMerge.getFirstRow().Part) { SamePart = false; } }); //Check to see if trigger is false - if so, display error if(SamePart === false) { skuid.$.blockUI({ message: '

Cannot merge two different parts

' }); }

Forgot to mention, this is running on a mass action - I believe part of the problem is this is looping a lot of extra times.


I think you want to loop through the rows of the NumbersToMerge model, not through the definition of the model itself. Try replacing your $.each() line with this:

$.each(NumbersToMerge<b>.getRows()</b>, function(i, row){

That took care of the looping problems - also figured out I needed to look up Part__c and not Part, as that was showing as undefined. This definitely solved my issue, though, the validation is now working. Thank you!