Skip to main content

Objective: I’d like to use a single table within a single page include that,


  1. Returns the opportunities for a given account when passed an account Id

  2. Returns the opportunities for a given contact when passed a contact Id (via OpportunityContactRole)

Approach: I included the XML below, but here’s a summary of the models and conditions:
  1. Account model

  • Condition: Id = AccountId URL param (novaluebehavior=“noquery")
2) OpportunityContactRole model
  • Condition: Id = ContactId URL param (novaluebehavior=“noquery")
3) Opportunity model
  • Condition logic: 1 OR 2

    1. Condition 1: AccountId = Id from the Account model (novaluebehavior=“deactivate")

    2. Condition 2: Id is in the set of OpportunityId values from the OpportunityContactRoles model (novaluebehavior=“deactivate")


Problem: This works perfectly except for when both the Account model and the OpportunityContactRole model don’t have rows. In this scenario, both conditions on the Opportunity model are deactivated but the query is still executed, so we end up with a table of random opportunities.

Changing the "novaluebehavior” of the conditions on the Opportunity model from “deactivate” to “noquery” doesn’t work either because the query gets aborted if one of the first two models doesn’t have rows, which will always be the case.


XML:





















































































Can you set your source page to only send AccountId parameter if there is an Account Id to send? The conditions have options as to what to do if a URL parameter is not found. One is deactivate condition. So, you could change your condition logic to 1 AND 2, then have the condition for AccountId deactivate if that parameter is not in the URL and the same for the ContactId.


I’m trying to keep all of the logic consolidated in the page include, so I’d like to pass the AccountId whenever the page include is viewed from an account detail and the ContactId whenever the page include is viewed from an contact detail.

I also don’t think that would solve for scenario I described above (i.e. I’d still get a random list of opps). 


You are correct. I whiffed on that one. Try three models: 1) an account model with a condition of receive your accountid parameter 2) a contact model to receive your contactid parameter 3) your primary model that has two conditions set to “in rows of another model”. Set the condition logic to 1 OR 2.


That’s essentially what I have already except that I’m sending the ContactId to the OpportunityContactRole model, which I’m then using the conditions of my primary model.


Will,

I think you are going to need to add an ‘Inline’ snippet to determine when to load the Opportunity model.  I don’t think there is a declarative solution for this.

Thanks,

Bill


Will, 
What do you want to happen? Do you want the table to show as blank? Do you want anything else to show instead? You could add rendering conditions on the table to hide it if both the oppcontact model and the account model don’t have data rows. That may not be ideal depending on your use case, but at least your users wouldn’t see a table of random opportunities. Another option would be to have two opportunity models on the page and two tables, one for each condition. You could render the proper one based on which model has data rows


I would like the query to be aborted when all models referenced in the conditions have no rows, which would result in a table with no rows vs what’s happening now, which is a table filled with random records.

My assumption is that even if I did hide the table when the other models don’t have rows, the query for the table is still executed, which would impact performance.

Having multiple models and tables for the different scenarios is an option I’ve considered, but I’m attempting to reduce redundancies wherever I can so that my pages load faster and they’re easier to maintain. 


Do you (or anyone else) have an example of what that might look like? I’m not opposed to a snippet, as long as it’s relatively straightforward.


Will,

This will get you started.  It needs to be ‘Inline’ JavaScript so that it runs on page load.


(function(skuid){<br>var $ = skuid.$;<br>$(document.body).one('pageload',function(){<br>//when the page loads into the browser<br>//check to see if the id parameter has a value. &nbsp;if so load the account model<br>if(window.location.href.indexOf('id=') != -1) {<br> &nbsp; &nbsp;//sets the id condition of the account model<br> &nbsp; &nbsp;skuid.model.map().Account.cancel();<br> &nbsp; &nbsp;var accountModel = skuid.model.getModel('Account');<br> &nbsp; &nbsp;var accountCondition = accountModel.getConditionByName('Id');<br> &nbsp; &nbsp;accountModel.setCondition(accountCondition, &nbsp;window.location.href.split('id=')i1])<br> &nbsp; &nbsp;accountModel.updateData();<br>}<br>});<br>})(skuid);


Thanks,

Bill


Reply