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

  • 1
  • Problem
  • Updated 1 year ago
  • Solved
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: '<h1>Cannot merge two different parts</h1>' });
}
Photo of Lucas Villanueva

Lucas Villanueva

  • 282 Points 250 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Lucas Villanueva

Lucas Villanueva

  • 282 Points 250 badge 2x thumb
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.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Lucas,

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.getRows(), function(i, row){
Photo of Lucas Villanueva

Lucas Villanueva

  • 282 Points 250 badge 2x thumb
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!