RE: NetSuite – SuiteScript 2 Need to rename Vendors while displaying

I am newbie to NetSuite and wanted to show vendor names in specific format while displaying. Currently each vendor has auto-generated id with some prefix e.g.

ABC0001
ABC0002
ABC0003

These vendors are then shown as a sublist in other pages as following:

ABC0001 Mr. Vendor A
ABC0002 Mr. Vendor B
ABC0003 Mr. Vendor C

I want to show vendor name as Name only, without the id in sublists like below:

Mr. Vendor A
Mr. Vendor B
Mr. Vendor C

How is that possible? Currently I tried to use following SuiteScript, but its not working:

define(["N/record"], function (record) {
  /**
   *@NApiVersion 2.0
   *@NScriptType ClientScript
   */

  function pageInit(context) {
    var itemRecord = record.load({
      type: record.Type.INVENTORY_ITEM,
      id: context.currentRecord.id,
      isDynamic: false,
    });

    var lines = itemRecord.getLineCount({ sublistId: "itemvendor" });

    for (var i = 0; i < lines; i++) {
      var vendorName = itemRecord.getSublistText({
        sublistId: "itemvendor",
        fieldId: "vendor",
        line: i,
      });

      var parts = vendorName.split(" ");
      parts.shift();
      vendorName = parts.join(" ");

      itemRecord.setSublistText({
        sublistId: "itemvendor",
        fieldId: "vendor",
        line: i,
        text: vendorName
      });
    }

    itemRecord.save();
  }

  return {
    pageInit: pageInit,
  };
});

Any idea what am I doing wrong here? Or is this even the right way to do it? Any help will be greatly appreciated.

Thanks

hrehman200 Rookie Asked on January 21, 2023 in Vendors.
Add Comment
1 Answers

The value you are getting for the field vendor in the itemvendor sublist is the id and not the name of the vendor. You will need to load the vendor record to get the name (companyname) of the vendor.

Beginner Answered on January 23, 2023.

Even if I get company name, how will I display it instead of vendor id?

on January 23, 2023.
Add Comment

Your Answer

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