Skip to main content

I’ve referenced these 2 posts (here and here), and both say returning false should stop the successive actions from running…but I’m having no luck.


var params = argumentsu0];
var step = params&#46;step; var $ = skuid&#46;$; &#47;&#47; Get Incentive and Template Requirements models var models = skuid&#46;model&#46;map(); var requirements = models&#46;TemplateRequirement; var incentive = models&#46;Incentive; &#47;&#47; Get fields from each model for use in validation var incentiveRow = incentive&#46;getFirstRow(); var incentiveStart = incentive&#46;getFieldValue(incentiveRow, "Incentive_Start_Date__c"); var incentiveEnd = incentive&#46;getFieldValue(incentiveRow, "Incentive_End_Date__c"); &#47;&#47; for each Template Requirement, validate the Milestone Date is within range of the Incentive Start and End Dates&#46; $&#46;each(requirements&#46;getRows() ,function(){ var requirementRow = this; var milestone = requirements&#46;getFieldValue(requirementRow, "Milestone_Date__c"); if (milestone < incentiveStart) { alert("Milestone Date(s) can not be prior to the Incentive Start Date"); return false; } else if (milestone > incentiveEnd) { alert("Milestone Date(s) can not be later than the Incentive End Date"); return false; } });

If I’m doing something blatantly obvious and wrong, please be kind 🙂 This is the first block of code I’ve ever written from scratch.

Using the branch action will certainly do the trick.


I thought about that, but what formula am I supposed to use?


Conlan,


The problem is that you’re returning false inside the $.each() function. That means you’re exiting the .each(), but not returning false for the whole snippet.


Try something like this:


&#47;&#47; for each Template Requirement, validate the Milestone Date is within range of the Incentive Start and End Dates&#46; var returnVal = true; $&#46;each(requirements&#46;getRows() ,function(){ var requirementRow = this; var milestone = requirements&#46;getFieldValue(requirementRow, "Milestone_Date__c"); if (milestone < incentiveStart) { alert("Milestone Date(s) can not be prior to the Incentive Start Date"); returnVal = false; &#47;&#47; return false; &#47;&#47;also do this if you want to exit the &#46;each() } else if (milestone > incentiveEnd) { alert("Milestone Date(s) can not be later than the Incentive End Date"); returnVal = false; &#47;&#47; return false; &#47;&#47;also do this if you want to exit the &#46;each() } });
return returnVal;

Matt, this worked great. Much appreciated for the assistance!


Reply