How would I create/set a preferred vendor when cre...
# suitescript
s
How would I create/set a preferred vendor when creating a new item through suitescript (preferred vendor is required because the inventory item is a dropship item)?
t
@Stephen Elms I do it by creating an "itemvendor" sublist line:
// Select the next sublist line.
theRecord.selectNewLine( { sublistId: 'itemvendor' } );
// Set the sublist values...
theRecord.setCurrentSublistValue(
{
sublistId: 'itemvendor',
fieldId: 'vendor',
value: 1234
}
);
theRecord.setCurrentSublistValue(
{
sublistId: 'itemvendor',
fieldId: 'purchaseprice',
value: 123.45
}
);
theRecord.setCurrentSublistValue(
{
sublistId: 'itemvendor',
fieldId: 'preferredvendor',
value: true
}
);
// Commit the sublist line.
theRecord.commitLine( { sublistId: 'itemvendor' } );
👀 1
s
Thank you for the info. I'm close, but not quite there. How do I weave your logic in to the inventory item creation logic. Here is my code after several passes. I'm getting the following error:
USER_ERROR Please enter value(s) for: Vendor
@erictgrubaugh 👆? Or, @tdietrich?
b
id start removing the fields that dont exist
s
What do you mean? Which one(s) don't exist?
b
take a look at the field help in the ui of the fields you are trying to set
👀 1
use the internal id listed in the help
s
Sadly, can't look at ID's in the UI for sub-lists.
b
i usually load an existing record in suitescript to look at the sublist fields
Copy code
require(["N/record"], function (record) {
  console.debug(record.load({ type: "inventoryitem", id: 68 }).toJSON());
});
👍 1
the less accurate trick of viewing the record's xml by setting the xml query parameter of the url to T (&xml=T) also works
t
@Stephen Elms Did you get this worked out?
s
@tdietrich Nope, still not working.
Here is what my code currently looks like, and the error:
USER_ERROR Please enter value(s) for: Vendor
b
you probably want to get to hardcoding your field values instead of using variables
your code looks reasonable and should give you an error about missing the mandatory itemid
you probably also want to take a look at the stack of the error to see where the error is
t
I would confirm that you really are passing in a valid vendor. Maybe try adding this:
log.audit({ title: 'vendor.internalId', details: vendor.internalId });
Also, try running the script without setting an itemvendor sublist record, and see what happens.
s
Yeah, that was part of the problem. I've confirmed that I have a valid vendor. 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"} }
I'm getting the following error:
"Drop ship/Special order items must have a preferred vendor and purchase price."
Peferred vendor and purchase price are specified, so there must be something wrong with the way I'm setting/creating the itemvendor sublist? My code now looks like:
t
It sounds like you're making progress. One more suggestion: Log the itemRecord just before saving it:
log.audit({ title: 'itemRecord', details: itemRecord });
That might shed some light on what values have (and have not) been set.
👍 1
s
itemRecord is to large to effectively log. Tried earlier suggestion of saving items without the vendor item specified. As long as I set dropship to false this works nicely.
t
Ok, so this is a longshot... Try setting the "dropship" field after setting the sublist record.
s
I finally got this to work... 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.