attach / detach

In SOAP web services, you can use the attach and detach operations to define or remove a relationship between two record instances. For example, you can associate a contact record instance with a partner record instance, or a file record instance with an opportunity record instance.

SOAP Request

In the following example, a contact record is attached to a customer record.

            <attach xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
 <attachReferece xsi:type="ns1:AttachContactReference"
     xmlns:ns1="urn:core_2017_1.platform.webservices.netsuite.com">
     <ns1:attachTo internalId="176" type="customer" xsi:type="ns1:RecordRef">
       <ns1:name xsi:type="xsd:string">Adelina Shonkwiler</ns1:name>
         </ns1:attachTo>
      <ns1:contact internalId="1467" xsi:type="ns1:RecordRef"/>
        <ns1:contactRole internalId="-10" xsi:type="ns1:RecordRef">
           <ns1:name xsi:type="xsd:string">Primary Contact</ns1:name>
         </ns1:contactRole>
  </attachReferece>
</attach> 

          

In the following example, a contact record is detached from a customer record.

            <detach xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
  <detachReferece xsi:type="ns1:DetachBasicReference"
        xmlns:ns1="urn:core_2017_1.platform.webservices.netsuite.com">
         <ns1:detachFrom internalId="176" type="customer" xsi:type="ns1:RecordRef">
          <ns1:name xsi:type="xsd:string">Adelina Shonkwiler</ns1:name>
              </ns1:detachFrom>
  <ns1:detachedRecord internalId="1467" type="contact" xsi:type="ns1:RecordRef"/>
    </detachReferece>
</detach> 

          

SOAP Response

The following example shows the response to an attach request.

            <attachResponse xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
   <writeResponse>
     <ns1:status isSuccess="true"
           xmlns:ns1="urn:core_2017_1.platform.webservices.netsuite.com"/>
          <baseRef internalId="176" type="customer" xsi:type="ns2:RecordRef"
                 xmlns:ns2="urn:core_2017_1.platform.webservices.netsuite.com">
              <ns2:name>Adelina Shonkwiler</ns2:name>
           </baseRef>
    </writeResponse>
</attachResponse> 

          

The following example shows the response to a detach request.

            <detachResponse xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
   <writeResponse>
     <ns1:status isSuccess="true"
         xmlns:ns1="urn:core_2017_1.platform.webservices.netsuite.com"/>
        <baseRef internalId="176" type="customer" xsi:type="ns2:RecordRef"
               xmlns:ns2="urn:core_2017_1.platform.webservices.netsuite.com">
             <ns2:name>Adelina Shonkwiler</ns2:name>
          </baseRef>
   </writeResponse>
</detachResponse> 

          

In REST web services, currently, the only records that can be attached or detached are contacts and files.

Attach and detach operations are defined using the !attach and !detach actions as part of the URL in the record REST service, which is called via the POST HTTP method. In the request body, you can specify optional attachment attributes for the attach operation, such as setting the role for attaching a contact. The request body can be empty if no optional attachment attributes are set. The content type of the request body is application/json.

To attach or detach two records, the record type and IDs of the record instances are required. All this information is part of the URL. The record type and ID of the instance to which the record is being attached or detached are defined after the version specification. The record type and ID of the record instance being attached or detached are defined following the operation identifier.

REST Request

The following example shows how to attach a contact record instance to a customer record instance.

            POST .../services/rest/record/v1/customer/660/!attach/contact/106
 
Content-Type: application/json
{
  "role": {
    "id": "-10"
  }
}
 
or
 
empty body or {} 

          

The following example shows how to detach a contact record instance from a customer record instance.

The URL structure for the detach operation must be constructed in a way that you first specify the record type and record instance ID after the v1 API version from which you are detaching a record instance.

Then, the record type and record instance ID that you are detaching is specified at the end of the URL.

            POST .../services/rest/record/v1/customer/660/!detach/contact/106
 
empty body 

          

Related Topics

General Notices