Forms: How to display Address, Phone, Email of Contact or Company field

You can use the Formula field to display data related to a contact or company field (e.g. address, phone, email) in your Form.

Example: you have defined a Form Template with the field F1 of type contact and F2 of type company

Create a New field of type Formula in the Template, and enter the following in the Default Value textbox:

  • To display the address:

var contact=Query.selectId("Contacts.contacts", F1);
if (contact!=null) Format.address(contact.street, contact.city, contact.state, contact.zipcode, contact.country)
else "";

or

var company=Query.selectId("Contacts.companies", F2);
if (company!=null) Format.address(company.street, company.city, company.state, company.zipcode, company.country)
else "";

  • To display the phone:

var company=Query.selectId("Contacts.companies", F2);
if (company!=null) Format.phone(company.phone);
else "";

  • To display the email:

var company=Query.selectId("Contacts.companies", F2);
if (company!=null) company.email;
else "";

Advertisements

9 thoughts on “Forms: How to display Address, Phone, Email of Contact or Company field

    • Yes, here is the script for the company name of a contact:

      var contact=Query.selectId(“Contacts.contacts”, F1);
      if (contact!=null) {
      var company=Query.selectId(“Contacts.companies”, contact.companyid);
      if (company!=null) company.name
      else “”;
      }
      else “”;

  1. Here is the script to get the custom field value of a linked Contact, where the ID of the contact custom field is C1. F1 is the ID of the Contact field in the Form.

    var contact=Query.selectId(“Contacts.contacts”, F1);
    if (contact!=null) {
    var objValues = CustomFields.loadValues(contact.custom);
    objValues[‘C1’];
    }
    else “”;

  2. Nice, but how is it possible to refer a linked record field in the form (e.g. when the form is created from a Company or a Contact)? I think that in this case the ID of the field is not “F” followed by an integer.

  3. Nice! Is it possibile to refer a linked record (e.g. when a form is created from a contact to refer that contact)? I think that in this case the ID of linked field is not “F” followed by an integer.

    • In this case, you must use the ‘link’ variable to reference the Linked record.

      if (link!=null) {
      var objValues = CustomFields.loadValues(link.custom);
      objValues[‘C1’];
      }
      else “”;

  4. Dear Nathalie, I’m trying to show company name of a linked contact in a formula field with this code:

    if (link!=null) link.company; else “”;

    But the result is always blank. If I put link.name the name of the contact is correctly shown, but I don’t need the name of the contact, I need the name of the company.

    Could you please suggest something else? Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s