Adding Conditions to an Extant Model. Is it possible?

  • 1
  • Question
  • Updated 2 years ago
Hi Guys,

I've got a use case where I want to filter a model based on varied conditions that a user might select. The problem is that I don't know what these conditions will be ahead of time.

So my question:

Is it possible to add conditions to a model at dynamically at run-time? I don't mean activating quiescent conditions with setCondition, but rather adding a totally new condition and re-querying an existing model.

I've tried variants of this type of thing, but just can't get the new condition into the query.

var tasksModel = skuid.$M('Tasks');
tasksModel.conditions.push({ type: 'fieldvalue', field: 'Id', operator: '=', value: 'Apple', inactive: false, name: 'Apple', encloseValueInQuotes: true }) tasksModel.initialize().register().updateData(); tasksModel.soql;


Any ideas would be greatly appreciated.

Thanks,
Dan Arnison
PractiFI
Photo of Dan Arnison

Dan Arnison

  • 320 Points 250 badge 2x thumb
  • existential

Posted 2 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

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

I would have expected what you're doing there to work.
Perhaps include
tasksModel.isInitialized = false;
 before you initialize and query again?

Perhaps try creating a 'blank' condition, and modifying the values of that condition via javascript?

Alternatively, you can just dynamically create the whole model.
Photo of Dan Arnison

Dan Arnison

  • 320 Points 250 badge 2x thumb
Thanks Matt. I gave that a try; no joy.

Also, I cannot readily create a new model dynamically because existing components are bound at design time.