RE: Is there a way to create a Vendor from a Customer as an Other Relationship using SuiteScript?

We need to generate 5000 new, linked Vendors from existing Customer records using a server-side SuiteScript (map/reduce, scheduled script).  Is there a way to create a Vendor record from a Customer record and link them as an Other Relationship using a server-side script?

a2metalcore Rookie Asked on March 3, 2021 in SuiteScript.
Add Comment
1 Answers
Best answer

The safe bet is to create your 5000 vendors as new vendors and then use an EntityDeduplicationTask to merge your new vendors into your original customers.

The unsupported way is to use record.transform to transform your customer into the vendor you want to save.

The lame SuiteAnswer way is to essentially programatically navigate to the url that creates the relationship after you create/edit the customer. Minor effort can be made to write javascript code that does the navigation without requiring a record submit.

Intermediate Answered on March 3, 2021.

Can’t seem to get either of those approaches to create an ‘Other Relationship’ by associating an existing customer with an existing vendor or  creating a new associated vendor from an existing customer. The requirement is to perform the same functionality as the Relationships/Other Relationships popup in the Customer app which appears to update a multi-select field called ‘customer.otherrelationships’ which is not available in the API. The record.transform method appears to ignore “toType: ‘vendor'” when using “fromType: ‘customer'”.

var CUSTOMER_ID = 2725;
varcustomerRecord = record.transform({
fromType: record.Type.CUSTOMER,
toType: record.Type.VENDOR,
isDynamic: true,
The EntityDeduplicationTask returns “Failed to submit job request: Inserted entity is not of declared primary flavor”:
var CUSTOMER_ID = 2728;
var VENDOR_ID = 6768;
var dedupeTask = task.create({ taskType: task.TaskType.ENTITY_DEDUPLICATION });
dedupeTask.entityType = task.DedupeEntityType.CUSTOMER;
dedupeTask.dedupeMode = task.DedupeMode.MAKE_MASTER_PARENT;
dedupeTask.masterSelectionMode = task.MasterSelectionMode.SELECT_BY_ID;
dedupeTask.masterRecordId = CUSTOMER_ID;
dedupeTask.recordIds = [VENDOR_ID];
var dedupeTaskId = dedupeTask.submit();

on March 4, 2021.

You will need to be more clear about whats wrong with the record.transform, your code looks fine to me

require(["N/record"], function (record) {
 var customer = record.create({ type: record.Type.CUSTOMER });
 customer.setValue({ fieldId: "companyname", value: "Company " + });
 customer.setValue({ fieldId: "subsidiary", value: "1" });
 var customerId =;
 try {
  record.load({ type: record.Type.VENDOR, id: customerId });
 } catch (e) {
  log.error("im not a vendor yet");
   fromType: record.Type.CUSTOMER,
   fromId: customerId,
   toType: record.Type.VENDOR,
   isDynamic: true,
 log.debug("im a vendor now", record.load({ type: record.Type.VENDOR, id: customerId }));
 log.debug("and still a customer", record.load({
  type: record.Type.CUSTOMER,
  id: customerId,

on March 4, 2021.

Choose the correct mode for the EntityDeduplicationTask. You want to merge rather than set the parent.

The entity type should also match the record type of the record being merged into the parent. It should not match the record type of the parent

on March 4, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.