Error creating dropship inventory item with SuiteScript

228 views Asked by At

I'm getting the following error:

"Drop ship/Special order items must have a preferred vendor and purchase price."

From this SuiteScript function which contains value assignments for preferred vendor and purchase price. So, there must be something wrong with the way I'm setting/creating the itemvendor sublist?

    function createItemRecord(item, vendor, subsidiary) {
        log.audit({
            title: 'createItemRecord...',
            details: {ITEM: item, VENDOR: vendor, SUBSIDIARY: subsidiary}
        });
        var itemRecord = record.create({
            type: record.Type.INVENTORY_ITEM,
            isDynamic: true
        });
      
       itemRecord.setValue({
            fieldId: "itemid",
          value: item.sku
        }).setValue({
            fieldId: "displayname",
          value: item.summary
        }).setValue({
            fieldId: "purchasedescription",
          value: item.details
        }).setValue({
            fieldId: "isspecialorderitem",
          value: true
        }).setValue({
            fieldId: "cost",
          value: item.price
        });
      
       itemRecord.selectNewLine({
          sublistId: 'itemvendor'
        });
      
      itemRecord.setCurrentSublistValue({
            sublistId: 'itemvendor',
            fieldId: 'vendor',
            value: vendor
          });
      /* vendor.internalId */
      itemRecord.setCurrentSublistValue({
            sublistId: 'itemvendor',
            fieldId: 'purchaseprice',
            value: item.price
          });
      
      itemRecord.setCurrentSublistValue({
            sublistId: 'itemvendor',
            fieldId: 'subsidiary',
            value: subsidiary.internalId
          });
      
      itemRecord.setCurrentSublistValue({
            sublistId: 'itemvendor',
            fieldId: 'preferredvendor',
            value: true
          });
      
      itemRecord.commitLine({
          sublistId: 'itemvendor'
        });
      
      itemRecord.save({
          enableSourcing: true,
          ignoreMandatoryFields: false
        });
    }

The audit log message at the start of the function indicates the following values are being passed in to the function:

{"ITEM":{"sku":"SKU #1","catalogcode":"1804","summary":"Billiard Table","details":"Billiard Table","price":9999.99}, "VENDOR":"1648", "SUBSIDIARY":{"internalId":"3","externalId":"","type":"subsidiary"} }

1

There are 1 answers

0
littlegreendude On BEST ANSWER

I'm not sure why it has to work this way, but what I did to fix this was move setting the special order item flag outside of the createItemRecord function. The createItemRecord will setup up the item including the sublist vendor item and save the record. Return the new record id to the caller. The caller passes this record id to a function to update the record by setting the special order item flag to true.

function createItemRecord(item, vendor, subsidiary) {

...

      var recordId = itemRecord.save({
          enableSourcing: true,
          ignoreMandatoryFields: false
        });
      
      return recordId;
    }
  
  function makeItemSpecialOrder(itemId)
  {
    log.audit({
      title: 'makeItemSpecialOrder...',
      details: itemId
    });
    
    var itemRecord = record.submitFields({
      type: record.Type.INVENTORY_ITEM,
      id: itemId,
      values: {
        isspecialorderitem: true
      },
      options: {
        enableSourcing: false,
        ignoreMandatoryFields: true
      }
    });
  }