Is it possible to create a row-action button to push contact field to custom object field

We have a phone field on the contact level, and would like to push it to our custom object “family” level by clicking a button or checking a box. Workflow rules don’t help us here because cross-object workflow rules don’t work for custom objects. There is a one-to-many relationship with families and contacts, so there will always only be one related family to a contact. This is critical functionality for our org, so please let us know of any possible solutions.

So if I understand this correctly: you have an object called “Family” (or Account), and then you have a Lookup field on the Contact object called something like “Family__c” (or AccountId) that lets you select a Contact’s related Family (Account). And then on the Family__c / Account object, you have a Phone field called “Family Phone” (or Phone) or something like that. Then, you have a “Family detail” (Account detail) Skuid Page, with a table of related Contacts. You want a Row Action on your Contacts table that takes the Contact’s Phone number and pushes it into the “Family Phone” (Phone) field on the contact’s related Family / Account record. Here is basically how it would work. Here we are using the Account object as the parent: TO make this work, you just need to have a Phone field on the parent / Account / Family model, a Phone field in your child / Contact model, and you need to add a Row Action of type “Custom / Run Snippet” to your Contacts Table. Create a new JavaScript Resource of type Inline Snippet, named “UseContactPhoneAsAccountPrimary”, with this as the body of the Snippet. You’ll need to edit the variables in the “Settings” area to configure the Snippet appropriately to point to your Account / Family Model’s name/id, as well as to specify the Ids of the Phone fields on your Contact and Family models that you want to copy into / from:

// // Settings // var CONTACT_PHONE_FIELD = 'Phone'; var PARENT_MODEL_ID = 'AccountsData'; var PARENT_PHONE_FIELD = 'Phone'; var SAVE_PARENT_MODEL_IMMEDIATELY = true; // // DO NOT ALTER // var model = arguments[0].model, row = arguments[0].item.row, parentModel = skuid.model.getModel(PARENT_MODEL_ID); if (!parentModel) alert('Could not find a Model with Id: ' + PARENT_MODEL_ID); parentModel.updateRow( parentModel.getFirstRow(), PARENT_PHONE_FIELD, model.getFieldValue(row,CONTACT_PHONE_FIELD,true) ); if (SAVE_PARENT_MODEL_IMMEDIATELY){ parentModel.save(); } 

There is also a setting here called “SAVE_PARENT_MODEL_IMMEDIATELY” that you can set to false if you do NOT want the Parent model to be immediately saved when you click the Row Action on the Contacts table.

Thanks Zach! Will test this out tomorrow. The only other similar thing to this we’ll need to do is for the task object. Tasks are also associated with families (not accounts) in a one-to-many relationship. We would like a row action to modify a date on the family called “last contacted date” when clicked, based on the ActivityDate activity field. How would I be able to manipulate the settings to work for the task object? Is it as simple as changing var CONTACT_PHONE_FIELD = ‘Phone’; to ActivityDate = ‘Date’ as long as it was a table based on the task model?

Yes you could reuse this for your Task scenario just by changing your settings to be:

// // Settings // var CONTACT_PHONE_FIELD = 'ActivityDate'; var PARENT_MODEL_ID = 'FamilyData'; var PARENT_PHONE_FIELD = 'Last_Contacted_Date__c'; var SAVE_PARENT_MODEL_IMMEDIATELY = true; 

assuming that your Family model is named “FamilyData” and your Family contacted date field is named “Last_Contacted_Date__c”. Don’t change the names of the variables (e.g. leave “CONTACT_PHONE_FIELD” alone, as this will mess up the code.

if I update this bit of code, can I change it away from Parent_Phone_Field? parentModel.updateRow( parentModel.getFirstRow(), PARENT_PHONE_FIELD, <---------------------- model.getFieldValue(row,CONTACT_PHONE_FIELD,true)

yeah, as long as you change the variable names throughout the snippet, you can change it however you want.

Hey Zach, this is great. Works perfectly, and the code makes a perfect sense! Thanks!

Zach, I’ve gotten a lot of use out of this little bit of code. I’d like to make a little modification to this, and I imagine it’s rather simple to do. In a list of all tasks for the company, if the task is linked to a contact, how can I look up the household or account id to select the appropriate one to update the field?