cross model linked conditions

Joe,  I don’t immediately see anything wrong with your code.   Would you mind giving us login rights to your org so we can take a look at what is going on?   Here is how:
1. Use this tutorial to give us login rights: http://help.skuidify.com/m/getting-started/l/182412-getting-help-how-to-grant-skuid-login-rights-to-….
2. Then send an email to support@skuidify.com  with the name of the page. 
We’ll see what’s going on…

Here are  a few clarifications we found about Pat’s snippet. 

1. Implementation: 
- This snippet should be of type “Inline Snippet”
- You need to create a model action on the first model (the one that has filters on it) that is triggered when you requery the model. 
- The actions need to be “Run Snippet” and “Query Model” - choosing the second model. 

2. Limitations: 
- This code will not work for multipicklist conditions.  There is a diffent API method for passing values into multi-picklist conditions. 

You guys are geniuses, and by geniuses, I mean the kind of people whose code the rest of us cannibalize so we can live another day without learning Javascript.

Here’s the XML for a page that demonstrates this in action, for my fellow copy-pasters. It has 3 models queried with one filter, that I created for this topic. Yay!

``` Contacts Tasks models.loaded This filter, though. Leads Contacts Tasks Leads Contacts Tasks Leads Tasks var $ = skuid.$, Leads = skuid.$M('Leads'), Contacts = skuid.$M('Contacts'), Tasks = skuid.$M('Tasks'); $.each(Leads.conditions, function(i,condition){ var LeadConditionName = condition.name, ContactsCondition = Contacts.getConditionByName(LeadConditionName) TasksCondition = Tasks.getConditionByName(LeadConditionName); if(condition.inactive) { Contacts.deactivateCondition(ContactsCondition), Tasks.deactivateCondition(TasksCondition); } else { Contacts.activateCondition(ContactsCondition); Contacts.setCondition(ContactsCondition,condition.value); Tasks.activateCondition(TasksCondition); Tasks.setCondition(TasksCondition,condition.value); } }); .hidetablefooter .nx-list-footer { display:none; } ```

Hi Ana,

Should this work with using a Date Range filter. 

Thanks,

Tami

I would not be suprised if this DOES NOT work with Date Range filters. 

So far I have not been able to get this to work with a Date Range. Do you know of another way that a date range can work on a table and its drawer?

interesting. Table model and drawer model. Should still work. You may have to modify snippet slightly.

Not sure about updating already opened drawer though.

Tami / Rob - 

If you use a date range with manual conditions it should work (I have it working on several pages). You may not be able to do it with the the automatically generated date range conditions.

Matt,

Can you explain more about the manual conditions? I have a date range with manual condition set on the parent table. How would I go about having it also change the drawer data?


Pat,

I tried your snippet with a date range and I couldn’t get it to work. Further inspection of how the date range shows in the console and the “value” section doesn’t get filled in. There are two conditions that need to be changed a Start and End date. Perhaps your snippet could work with some changes but I am not versed enough at this point to know what those changes should be.

Tami,

Here are two snippets, modified from Pat’s. The first I use to initialize the date range on the primary model on pageload. The second I use to link the conditions each time the primary model is queried. You need a conditions called “StartDate” and “EndDate” on each model that you want to link.

<jsitem location="inline" name="initializeDateConditions" cachelocation="false" url="">(function(skuid){
var $ = skuid&#46;$;
$(document&#46;body)&#46;one('pageload',function(){
var dateRangeModel = skuid&#46;$M('Cases'),
    startDateCondition = dateRangeModel&#46;getConditionByName('StartDate'),
    endDateCondition =  dateRangeModel&#46;getConditionByName('EndDate'),
    startDate = new Date(),
    endDate = new Date(),
    startDateOffset = -15,
    endDateOffset = -1;
    
    startDate&#46;setDate(startDate&#46;getDate() + startDateOffset);
        endDate&#46;setDate(endDate&#46;getDate() + endDateOffset);
    
        var startConditionValue = skuid&#46;time&#46;getSFDateTime(startDate),
            endConditionValue = skuid&#46;time&#46;getSFDateTime(endDate);
        
        dateRangeModel&#46;setCondition(startDateCondition, startConditionValue);
        dateRangeModel&#46;setCondition(endDateCondition, endConditionValue);
    
        dateRangeModel&#46;updateData();
    
});
})(skuid);</jsitem>
      <jsitem location="inlinesnippet" name="linkConditions" cachelocation="false">var $ = skuid&#46;$;
var startValue = skuid&#46;$M('Cases')&#46;getConditionByName('StartDate')&#46;value,
    endValue = skuid&#46;$M('Cases')&#46;getConditionByName('EndDate')&#46;value;
var targetModels = [];
targetModels&#46;push(skuid&#46;$M('numberOfSchedulingLeads'));
$&#46;each(targetModels, function(){
   this&#46;setCondition(this&#46;getConditionByName('StartDate'), startValue);
   this&#46;setCondition(this&#46;getConditionByName('EndDate'), endValue);
});
</jsitem>

After you run the linking script, you’ll need to query the linked (drawer) model.

Hi Matt,

I’m trying to use same principle to get this idea working, and wondering if you think it could work.

I have some sort of “Dashboard” built on Skuid, which contains 15+ models

And i want to Be able to input 1 Date Range manually (prob 2 ui only date fields , 1 for startdate , 1 for enddate- as cannot use automatically generated filters)

and once date range is inputted for it to affect all 15 models with same condition name

Any ideas?

This would certainly work. As Matt has done, you could name all the filters in each model with the same names so that you could create a snippet to loop through the models in order to update each of their conditions and then query them after which.

If you want to update every model in your page with your ui only fields, then you could loop through them using skuid.model.list(). If not, create an array of the model id’s to loop through in this way.

var models = [‘model1’,‘model2’,…],
      model;


$.each(models, function(m,modelid)({
   model = skuid.$M(‘modelid’)
   // update model conditions
   …
});

I’d just put a pagetitle with an ‘apply’ button next to your date range fields, and have the button run a snippet that goes something like this:

var $ = skuid&#46;$; $&#46;blockUI(); var row = skuid&#46;$M('MyUiOnlyModel')&#46;getFirstRow(), startValue = row&#46;StartDate &nbsp; &nbsp; endValue = row&#46;EndDate; var targetModels = skuid&#46;model&#46;list(); <br /> &#47;&#47; If you don't want to apply the condition to all of your models, &#47;&#47; you can list them manually in the targetModels array like so: &#47;&#47; var targetModels = [skuid&#46;$M('Model1'),skuid&#46;$M('Model2')]; <br />$&#46;each(targetModels, function(){<br />&nbsp; &nbsp;this&#46;setCondition(this&#46;getConditionByName('StartDate'), startValue);<br />&nbsp; &nbsp;this&#46;setCondition(this&#46;getConditionByName('EndDate'), endValue);<br />}); $&#46;when(skuid&#46;model&#46;updateData(targetModels))&#46;then(function(){ $&#46;unblockUI(); });

HI Matt & Pat,

Thank you and  Sorry was a bit busy and was only able to test this today.

I created a model named MyUiOnlyModel , and 2 Ui-only fields in it, named StartDate and EndDate
+ create 2 condition (filterable off) in 1 other model to test , condition are named StartDate and EndDate

Apply button has 1 Action: Run the Snippet above

When i try it, i get this error in console :  Uncaught Model ‘MyUiOnlyModel’ has unsaved changes. To update this model’s data, you must first save or cancel the changes.

On the model named ‘MyUiOnlyModel’, I unchecked the option to Prevent users from leaving page if this Model has unsaved change, but Still having same error

The UI is stuck and cannot test properly because of it.

Any Ideas?

Thank you

The “MyUiOnlyModel” must be set to query as well. You’ll have to cancel the changes prior to query but after setting conditions.

Thank you , been trying, but nothing works. i guess not knowledgeable enough in JS to modify Matt’s Script on my own :frowning:

In case any of you have a similar script you are already using please share, so i can try to understand it.


var $ = skuid.$;<br>
$.blockUI(); var row = skuid.$M('MyUiOnlyModel').getFirstRow(), startValue = row.StartDate &nbsp; &nbsp; endValue = row.EndDate; var targetModels = skuid.model.list(); <br> // If you don't want to apply the condition to all of your models, // you can list them manually in the targetModels array like so: // var targetModels = [skuid.$M('Model1'),skuid.$M('Model2')]; <br>$.each(targetModels, function(){<br>&nbsp; &nbsp;this.setCondition(this.getConditionByName('StartDate'), startValue);<br>&nbsp; &nbsp;this.setCondition(this.getConditionByName('EndDate'), endValue);<br>}); $.when(skuid.model.updateData(targetModels)).then(function(){ $.unblockUI(); });

Hi All,

I’ve also been trying to edit this snippet, to no avail. My use case:

  • Two different objects, both with a multipicklist that uses a global picklist
  • If I filter object A, I want object B to also filter

My code is below, where the two models in Skuid are named ‘Projects’ and ‘Focus_Area_Grouping’. The model is named "Focus_Area_Grouping’ in both objects.

var $ = skuid.$,    Projects = skuid.$M(‘Projects’),
    Focus_Area_Grouping = skuid.$M(‘Focus_Area_Grouping’);
    
    $.each(Projects.conditions, function(i,condition){
        
        var agConditionName = condition.name,
            Focus_Area_Groupings__c = Focus_Area_Grouping.getConditionByName(Focus_Area_Groupings__c);

        if(condition.inactive) {
            Focus_Area_Grouping.deactivateCondition(Focus_Area_Groupings__c);
        } else {
            Focus_Area_Grouping.activateCondition(Focus_Area_Groupings__c);
            Focus_Area_Grouping.setCondition(Focus_Area_Groupings__c,condition.value);
        }

    });


Additionally, I also tried this:
var $ = skuid.$, Projects = skuid.$M(‘Projects’),Focus_Area_Grouping = skuid.$M(‘Focus_Area_Grouping’);

$.each(Projects.conditions, function(i,condition){

var agConditionName = condition.name,
basicCondition = Focus_Area_Grouping.getConditionByName(agConditionName);
if(!agConditionName) {
return true;
} else if(condition.inactive) {
Focus_Area_Grouping.deactivateCondition(basicCondition);
} else {
Focus_Area_Grouping.activateCondition(basicCondition);
Focus_Area_Grouping.setCondition(basicCondition,condition.value);
}


Any help welcome!

If you’re only dealing with one condition, you don’t need the ‘$.each’.

Try something like this…

var $ = skuid.$, &nbsp; &nbsp; Projects = skuid.$M('Projects'),<br>&nbsp; &nbsp; Focus_Area_Grouping = skuid.$M('Focus_Area_Grouping');<br>&nbsp; &nbsp;&nbsp;<br>var projectsCondition = Projects.getConditionByName('Focus_Area_Grouping'),<br>&nbsp; &nbsp; focusAreaGroupingCondition = Focus_Area_Grouping.getConditionByName('Focus_Area_Grouping');<br>&nbsp; &nbsp; if(projectsCondition.inactive) {<br>&nbsp; &nbsp;Focus_Area_Grouping.deactivateCondition(focusAreaGroupingCondition);<br>} else {<br>&nbsp; &nbsp;Focus_Area_Grouping.setCondition(focusAreaGroupingCondition, projectsCondition.value);<br>}