Results 1 to 5 of 5

Thread: How do I set the value of a "Relate" type field in a module?

  1. #1
    john2x is offline Sugar Community Member
    Join Date
    May 2013
    Posts
    16

    Default How do I set the value of a "Relate" type field in a module?

    I added a custom field in the Accounts module, the field type is "Relate" and the module it relates to is "Contacts". (the field name is 'primary_contact_c')

    When I create/edit an account, how do I set this field to an existing contact? I tried 'set_relationship('Accounts', 'account-id', 'primary_contact_c', ['contact-id'])', but it fails.

  2. #2
    john2x is offline Sugar Community Member
    Join Date
    May 2013
    Posts
    16

    Default Re: How do I set the value of a "Relate" type field in a module?

    Anyone? I also tried directly setting the account's 'primary_contact_c' field to the ID of the contact, but it doesn't work. (Turns out the field stores the contact's name instead of it's ID. That's weird.)

  3. #3
    CastleBravo is offline Sugar Community Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    52

    Default Re: How do I set the value of a "Relate" type field in a module?

    I've noticed that with relate fields, it's not always the actual name of the field that you want to set, in your case 'primary_contact_c'. There's often a hidden input that Sugar attaches to these relate fields that you need to set instead. I usually need to inspect the relate field element with Firebug or Chrome's developer tools to see what the actual hidden input name is.

    So try adding your 'primary_contact_c' to the edit view of your module, and then go edit the record. Then right-click in the area of the the relate field where a user would type in the name of the contact, inspect the element, and look for a hidden input element that is a child of primary_contact_c. The actual field you need to update is likely the ID of that hidden input.

    I created a primary_contact_c myself just now, added it to the edit/detail view of the Accounts module and then inspected the element. There's a hidden input named 'contact_id_c' that would need to be set with the ID of the contact to relate with.

  4. #4
    CastleBravo is offline Sugar Community Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    52

    Default Re: How do I set the value of a "Relate" type field in a module?

    Name:  hidden input.png
Views: 69
Size:  11.3 KB

    Here's a screenshot of what I mean. If I inspect the 'primary_contact_c' relate field, you can see that there is a hidden input with an ID of 'contact_id_c' and that is what you would probably need to update with the ID of the contact to relate to. The hidden input ID may be different on your installation, however.

  5. #5
    john2x is offline Sugar Community Member
    Join Date
    May 2013
    Posts
    16

    Default Re: How do I set the value of a "Relate" type field in a module?

    That was it. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change Field type from TextField to Relate
    By prachisenad in forum Help
    Replies: 0
    Last Post: 2013-08-21, 10:28 AM
  2. Relate field of type Employee.
    By neel1154 in forum Developer Help
    Replies: 4
    Last Post: 2012-04-06, 05:40 AM
  3. custom field with data type: relate
    By 1joe in forum Developer Help
    Replies: 0
    Last Post: 2010-04-16, 01:59 AM
  4. customCode for a relate type field
    By gopalkalasa in forum Developer Help
    Replies: 0
    Last Post: 2009-06-10, 03:06 PM
  5. custom module custom field relate type error
    By kidpollo in forum General Discussion
    Replies: 0
    Last Post: 2007-03-24, 02:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •