<div dir="auto">It's really late.. But I may have a solution that goes about a totally different way. <div dir="auto"><br></div><div dir="auto">If I understand your logic - you could query all contracts into an array that are "related to" an organisation and then mark the most recently created one as the primary contact. Assuming you always want to have the most recent one set as primary? <br><br><div data-smartmail="gmail_signature" dir="auto">Regards,<br><br>CJC<br><br>(sent on the move)</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 18 Jun 2018, 21:45 Alex Hall, <<a href="mailto:ahall@autodist.com">ahall@autodist.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello list,</div><div>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:</div><div><br></div><div>* get $entity's "is primary" custom field value</div><div>* exit if the newly set value is false, as there's nothing to update</div><div>* get $entity's parent organization (remember that $entity is from a contacts workflow)</div><div>* set all the children contacts of $entity's parent organization to not be primary, while setting $entity itself to be the only primary</div><div><br></div><div>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.<br></div><div><br></div><div>-- <br><div class="m_463440088625530483gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div>Alex Hall<br></div>Automatic Distributors, IT department<br></div><a href="mailto:ahall@autodist.com" target="_blank" rel="noreferrer">ahall@autodist.com</a><br></div></div>
</div></div>
_______________________________________________<br>
<a href="http://www.vtiger.com/" rel="noreferrer noreferrer" target="_blank">http://www.vtiger.com/</a></blockquote></div>