Javascript Error

I am trying to write my first Javascript code to set the condition of one of my models, but I am getting an “Uncaught TypeError: undefined is not a function” message on my if statement and I’m not sure how to make this a function. I have tried to read other posts to figure this out, but I think that I have hit a wall with my little understanding of Javascript. I am trying to activate and set a condition if a checkbox on another the TableFilter model is checked.


var myModel = skuid.model.getModel(‘AlumniConnections’);
var myModel2 = skuid.model.getModel(‘TableFilter’);
var myModel3 = skuid.model.getModel(‘Admit’);
var DesiredIndustry = myModel.getConditionByName(‘DesiredIndustry’);

r = myModel2.getFirstRow();
s = myModel3.getFirstRow();

if (r.X1__c ===true) DesiredIndustry.setCondition(DesiredIndustry, s.Job_after_MBA__c);

Last line should be…

if (r.X1__c ===true) myModel.setCondition(DesiredIndustry, s.Job_after_MBA__c);

setCondition is a function on the model object, not the condition object.

Also, put var before your r = and s = variable declarations.  That way they won’t leak into the global scope.

Ok, I changed my code, but it still seems like it is not setting the value of the condition. When my results are displayed it is only returning results with blank values in the field. Does it matter that I am running this as a table row action and then a run javascript action? I have tried adding query model and save model after the run javascript, but that hasn’t helped either. Right now my condition is set to a value of single specified value and filterable default off with no grouping logic set. Here is what I change the code to.

var myModel = skuid.model.getModel(‘AlumniConnections’);var myModel2 = skuid.model.getModel(‘TableFilter’);
var myModel3 = skuid.model.getModel(‘Admit’);
var DesiredIndustry = myModel.getConditionByName(‘DesiredIndustry’);

var r = myModel2.getFirstRow();
var s = myModel3.getFirstRow();

if (r.X1__c ===true) myModel.setCondition(DesiredIndustry, s.Job_after_MBA__c);

When you set a model condition, you still have to explicitly requery the model if you want to get an update.  You’d have to put in the following code to make your model refresh.

myModel.updateData();

I tried adding this to the end, but the condition is still returning only blank values. I tried to debug it by using watched expressions, but it looks like setting the value after the if statement is returning an undefined value.

It looks like your DesiredIndustry variable is getting set to “false”.  That means that Skuid is not finding that condition on that model.  Two things I would check…

1. Is that the exact case-sensitive name of the condition on your model?
2. Is that condition inside of a subquery?  If so, you need to call getConditionByName() with a second parameter set to true.  This will search for subconditions as well.

That was it! In the condition of the model I had misspelled it and put DesiredIndusty instead of DesiredIndustry. 

Thank you for your help!