[Vtigercrm-developers] get entity parent in workflow custom function?

Alex Hall ahall at autodist.com
Mon Jun 18 22:11:35 GMT 2018

Thank you, I'll try that. So account_id holds the contact's parent's ID? I
wouldn't have guessed that. Although, now that you point it out, I'm
remembering that VT calls "organizations" "accounts" internally, so that
does make more sense. I'll also look at event handlers to see if that would
be a better fit.

A follow-up question, now that I think about it. Once I have the parent's
ID, what's the best way to get all the parent's child contacts? A DB call?
Web services? A simple method I don't know about? Thanks.

On Mon, Jun 18, 2018 at 5:12 PM, Alan Lord <alanslists at gmail.com> wrote:

> I think you mean the "account_id" field?
> Just "get" the entity data for the id in that field.
> $accid = $entity->get('account_id');
> I do the same kind of thing in several customer's systems where they need
> a Primary and perhaps a Signatory contact.
> FWIW I tend to use an Event Handler rather than a workflow as it can't be
> disabled as easily.
> Al
> On 18/06/18 20:42, Alex Hall wrote:
>> Hello list,
>> I've been asked to write a custom function for a workflow to run whenever
>> a contact is updated. We have a custom field called "is primary contact",
>> which is just a checkbox. However, each organization can only have one
>> primary contact at a time. That means the custom function has to move the
>> "primary" designation to the newly selected contact. Put another way, the
>> function has to do these tasks:
>> * get $entity's "is primary" custom field value
>> * exit if the newly set value is false, as there's nothing to update
>> * get $entity's parent organization (remember that $entity is from a
>> contacts workflow)
>> * set all the children contacts of $entity's parent organization to not
>> be primary, while setting $entity itself to be the only primary
>> My main problem right now is finding $entity's parent. I can't figure out
>> how to do that. I've looked at the source code, but there's nothing in that
>> class that seems to be a way of accessing the parent. What's the trick to
>> this, or can it not be done how I want? Is there another way anyone can see
>> to get this working? Hopefully I've explained enough to make sense. Thanks.
>> --
>> Alex Hall
>> Automatic Distributors, IT department
>> ahall at autodist.com <mailto:ahall at autodist.com>
>> _______________________________________________
>> http://www.vtiger.com/
> _______________________________________________
> http://www.vtiger.com/

Alex Hall
Automatic Distributors, IT department
ahall at autodist.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20180618/e6666769/attachment.html>

More information about the vtigercrm-developers mailing list