How to clear a relationship field

So how do you CLEAR a relationship field that has a value in it?  I tried

this.model.set('whatevercontracts_accountsaccounts_ida', '')
this.model.set('whatevercontracts_accounts_name', '');

but that doesn't really work, it seems to leave the name in place.  If I d
this.model.set('whatevercontracts_accountsaccounts_ida', '')
this.model.set('whatevercontracts_accounts_name', ' ');

(see space in the name), that clears the name but doesn't really reset the field.
  • I have also tried

    this.model.unset('whatevercontracts_accounts_name');

    with no luck.  

    Any ideas?

  • I would use an API call:

    DELETE /<module>/:record/link/:link_name/:remote_id deleteRelatedLink
    Check your sugarcrm/rest/v10/help for details on its usage.
    FrancescaS
  • Thats not exactly what I am looking for.  What I am trying to do is clear the field on a create or record view, like if I have a partner contact name selected (the person at an account) and then they clear or change the Partner (account) it should clear the Partner Contact relationship field as that person is no longer valid.  So I am not talking about clearing the field in the DB or deleting the relationship record, I am JUST talking about clearing the field on the screen.

  • In which case this should work:

    this.model.unset('whatevercontracts_accountsaccounts_ida')
    this.model.unset('whatevercontracts_accounts_name');

    You need to unset both the name and the id, though I would think that, logically, clearing the field in the create view should do that for you...

    FrancescaS

  • Yes, you can clear the field from the create view but we have fields that are related to that field and I want them to clear all at the same time.  Once you clear the parent relationship, I need related relationships to be cleared as well as they are now wrong.  I found the code that does it, you have to clear them both and then re-render the field.


    this.clearAllFields=function(self)
    {

            //Clear the partner contact
            self.model.unset('in_customer_contacts_cases_1_name');
              self.model.unset('in_customer_contacts_cases_1in_customer_contacts_ida');
              fieldRef = self.getField('in_customer_contacts_cases_1_name');
              fieldRef.render();

                    //clear the customer contact
              self.model.unset('contacts_cases_1_name');
              self.model.unset('contacts_cases_1contacts_ida');
              fieldRef = self.getField('contacts_cases_1_name');
              fieldRef.render();

                    //clear related address and phone fields
              self.model.set('service_address_street_c', '');
              self.model.set('service_address_city_c', '');
              self.model.set('service_address_state_c', '');
              self.model.set('service_address_postalcode_c', '');
              self.model.set('star2star_locationdid_c', '');
              self.model.set('customer_contact_phone_numbe_c', '');

              self.model.set('partner_contact_phone_number_c', '');
              self.model.set('partner_contact_email_c', '');
              self.model.set('customer_contact_email_c', '');
              self.model.set('customer_contact_phone_numbe_c', '');
              self.model.set('customer_contact_email_c', '');
              self.model.set('call_back_name_c', '');
              self.model.set('call_back_number_c', '');
              sessionStorage.removeItem('call_back_name_c');
              sessionStorage.removeItem('call_back_number_c');
         };