Skip to main content

We have a custom object called Households with related Contacts inside. We cannot use the Household as the WhatID for tasks. How can we create a condition for the task model which pulls all the activities related to the contacts inside the Household?

Hi Greg, Since you already have a contacts model on your page, you can use that to match a name to your custom WhoId field in your custom field renderer. Here would be the code to do something like that. Include this in your resources tab as and “inline (snippet)” type. Then reference that snippet in a custom field renderer on your custom WhoId field.


var $ = skuid.$; var field = argumentse0]; var value = argumentse1]; // Get the Contact model you already have on this skuid page var contactModel = skuid.model.getModel('Contacts'); // Search the contact model for a record with this id var contactRow = contactModel.getRowById(value); var link = $('<a>').prop('href','/' + value); if (contactRow) { link.text(contactRow.Name); field.element.append(link); } 

I forgot to add, make sure the Name field is in your Contacts model. I had just FirstName and LastName in my model when I was building this, and nothing showed up until I added the Name field to my model.


Ben - also to make sure - this script should be comparing the custom WHOID field on the activity to the custom “Old Contact ID” field on the contact record, and displaying a link to either the new contact record (or preferably straight to the family record). Does this script do that? It looks like it is comparing the “WHOID” to the new contact ID (which will not find a match), but I’m not a jquery expert either. My column is also blank, so that indicates something may be amiss.


In that case, you’ll need to try something like this…


var $ = skuid.$; var field = argumentse0]; var value = argumentse1]; // Get the Contact model you already have on this skuid page var contactModel = skuid.model.getModel('Contacts'); // Search the contact model for a record with this id var contactRow; $.each(contactModel.data,function(){ console.log(this); console.log(this.Old_Contact_Id__c); console.log(value); if (this.Old_Contact_Id__c === value) { contactRow = this; return false; } }); console.log(contactRow); var link = $('<a>').prop('href','/' + contactRow.Id); if (contactRow) { link.text(contactRow.Name); field.element.append(link); } 

Things to note, this custom renderer needs to be on the custom “WhoId” field. Otherwise, “value” will not be correct. I put in some console.logs so that you can check your javascript console and see what is going on. I may not have gotten your field names exactly right (they are case sensitive as well), but I think you can get the gist. If you get it working, you should remove the console.logs.


Ben, My page is still blank, and I’m getting the following error in my log: Uncaught TypeError: Cannot read property ‘Id’ of undefined


move the “var link…” line into the if statement below it, that will get rid of that error. You can also look in your console to see the output of those logs.


Ben - I loaded up my log into a pastebin - the page stopped going blank (In Chrome and IE10 - is still blank in IE9), but nothing is appearing in the column. The pastebin is set to expire in 1 day: http://pastebin.com/m20injiD


It looks like the problem is with this line… this.Old_Contact_Id__c This has to be the exact case sensitive name of your old contact field. This also must be included as a field in your contact model.


Ben, the exact field name is Old_Contact_ID__c (copied directly from the model) Here is my version of the two lines referencing that field: console.log(this.Old_Contact_ID__c); if (this.Old_Contact_ID__c === value) {


ok, one more thing I can think of, can you give me that same console output, but use Chrome’s console, or something that will show something other than “Object” for the output for that field? Sometimes you have to click the little arrow next the console output to drill into that log. I really need to see the contents of that “Object”.


Ben, I had to uncollapse each one manually in Chrome, so I only did a couple, but here’s another pastebin: http://pastebin.com/dj4nTZcJ


well, i’m at a loss, it seems like it should be working. Can you copy/paste your exact code for the snippet here, or grant Skuid LLC access to your org, so I can take a look?


Rob, I gave login access from our admin account to Skuidify LLC Support. Do you know when you might have time to take a look? Thanks so much!


Hi Greg, I logged into your org, and I’m assuming that the FamilyView page is what you were working on, but I didn’t see that field or snippet on the page. Should I be looking at a different page?


Hey Ben - it’s the HomePage skuid page.


Hi Greg, I took a look at your page. I was thinking this was for the same page as we worked on earlier. On the “HomePage” page, your contact model is not limited to just the contacts for a particular household. Since your Contact model does not have any conditions, it just pulls in all Contacts in your org, (up to the limit on the model which defaults to 100). This snippet will only work if you have the contacts already loaded into your contact model when the snippet runs. You could remove the limit on your contact query, but that could cause other problems, especially if you have a large number of contacts in your org. I’m not sure if this solution will work for your particular situation.


Thank you, Ben and Greg! I’m working with the Wealth Management edition (sounds like Greg is too), and just spent half the day wrestling with a similar issue. I was trying to get all activity onto an Individual page whenever their name was in WhatID or WhoID on the activity. Wish I’d seen your comments sooner. The key for me was that I had NO idea that it mattered what sequence the models were in on the tab. It made all the difference.


Reply