Netsuite | attach detach using .NET webservices

This is a sample code in .NET on how to use the attach/detach method on attaching and detaching a file record to an entity record on Netsuite webservice.

Here is how you can locate the files attached to an employee record:

List > Employees > Employees > Select an employee, in the ‘General’ tab there is a ‘File Cabinet’ subtab.

To locate the files in your Netsuite account:

Documents > Files > File Cabinet

Attaching a file record to an employee record:

//file record
RecordRef recFile = new RecordRef();
recFile.internalId = "373";
recFile.type = RecordType.file;
recFile.typeSpecified = true;

//employee record
RecordRef recEmployee = new RecordRef();
recEmployee.internalId = "470";
recEmployee.type = RecordType.employee;
recEmployee.typeSpecified = true;

//attach class
AttachBasicReference attachBasicRef = new AttachBasicReference();
attachBasicRef.attachedRecord = recFile;
attachBasicRef.attachTo = recEmployee;

WriteResponse response = _service.attach(attachBasicRef);
if (response.status.isSuccess) {
Response.Write("Successfully Attach a file record");
}
else {
Response.Write("Attaching file record, fail");
}

Detaching a file record to an employee record:

//file record
RecordRef recFile = new RecordRef();
recFile.internalId = "373";
recFile.type = RecordType.file;
recFile.typeSpecified = true;

//employee record
RecordRef recEmployee = new RecordRef();
recEmployee.internalId = "470";
recEmployee.type = RecordType.employee;
recEmployee.typeSpecified = true;

//detach class
DetachBasicReference detachBasicRef = new DetachBasicReference();
detachBasicRef.detachedRecord = recFile;
detachBasicRef.detachFrom = recEmployee;

WriteResponse response = _service.detach(detachBasicRef);

if (response.status.isSuccess) {
Response.Write("Successfully Attach a file record");
}
else {
Response.Write("Attaching file record, fail");
}

NOTE: The _service is a NetsuiteService class object. The login process is omitted in this sample code.

Related posts:

  1. Netsuite | How to get the value of custom fields using webservices in .NET application

One Comment

  1. Leslie says:

    What a great blog

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>