Compare 2 field values?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
What would the JS be for a snippet used to conditionally render a field by comparing 2 other fields to see if they are equal?  In other words, I want to highlight a row in a table if 2 field editor fields are not equal...
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
I'm trying to answer 2 of your questions at once... But basically you can run an Inline snippet on page load with something like this (which also compares fields...):

(function(skuid){	var $ = skuid.$;
$(function(){
   //this runs on page load 
   var firstModel = skuid.$M('FirstModel');
   var firstRow = firstBG.getFirstRow();
   var secondModel = skuid.$M('SecondModel');
   var fieldOne = firstRow.field_One__c;
var fieldTwo = secondRow.field_Two__c;
   if(fieldOne !== fieldTwo){
//do stuff here
       secondModel.updateRow(secondRow,'Your_Field__c',yourNewValue);
   }
});
})(skuid);
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
nice... thanks Moshe!