How to retrieve the generated URL value for a URL field type using the "generate" option?

The Sugar URL field type has a nice feature where it will generate a URL for you based on other fields on the record. For example, if you want to link to another system and pass the contact's Sugar record ID, you could have a custom field use the template "https://theothersystem.com/?id={id}" and when you view the record in Sugar, the link field will automatically generate the {id} part so that when you click the link it is properly filled in.

I'm wanting to retrieve this generated link value and use it in my custom code, the only issue is that when you pull the bean, the field does not give you the generated value. It will give you the template.

<?php 
// This doesn't work
// say I have a field, generated_url_c and it should be https://website.com/{id}
$record = BeanFactory::getBean('Contacts','1234-1234-1234-1234');
echo $record->generated_url_c;
// this will return https://website.com/{id}
// not https://website.com/1234-1234-1234-1234

How do I get the generated URL value on the server side? Is there a method we can run these URL fields through to get the generated value?

Thanks!

Parents
  • It looks like the apiFormatField() method is what needs to be called in includes/SugarFields/Fields/Link/SugarFieldLink.php. In that method you can see it checks the 'gen' value to see if it is flagged then runs a replace_sugar_vars() method to do the replacement.

    Any ideas how to run that method? Or is there a generic method you can run on a $bean that will run the apiFormatField() method for all fields on the bean?

    I'm guessing that is what is run whenever Sugar sends a $bean to the client for display in sidecar?

Reply
  • It looks like the apiFormatField() method is what needs to be called in includes/SugarFields/Fields/Link/SugarFieldLink.php. In that method you can see it checks the 'gen' value to see if it is flagged then runs a replace_sugar_vars() method to do the replacement.

    Any ideas how to run that method? Or is there a generic method you can run on a $bean that will run the apiFormatField() method for all fields on the bean?

    I'm guessing that is what is run whenever Sugar sends a $bean to the client for display in sidecar?

Children
No Data