We had this question asked internally here at Sugar the other day from one of our PS team members:
I am working on Smarty function to get related beans for MultienumField. Relationship Name, module and RHS field name is required for smarty function. Can I set these fields in vardef?
David Wheeler chimed in with a great solution to the problem, which should be helpful for any of us needing to leverage the vardefs to get more information for a related field.
You can’t directly get the relationship name or module from the vardef for relate fields in all cases. The Link field is what you need rather than the relationship name since that is how relationships are accessed.
If you have a relate field that a vardef with:
“rname” => “description”
“link” => “accounts”
you can then pull the related accounts description field with something similar to:
$value = ""; $link = $bean->field_defs[$field]['link']; $rname = $bean->field_defs[$field]['rname']; $bean->load_relationship($link); $related = $bean->$link->getBeans(); if (!empty ($related) && isset($related->$rname) $value = $related->$rname;
This assumes that $bean is the current working bean and $field is the name of the relate field.