Whoops! Fixing an Incorrect Costing Method

One of the problems we’ve faced after implementing NetSuite is having to fix an incorrect Costing Method on an item record. Once an item is created, the costing method is set and cannot be changed.

What is “Costing Method”? Its the way costs are assigned to inventory. Here are some examples: “First in First Out”, FIFO, “Last In First Out” LIFO, Average, By Lot, By Serial Number, etc. It’s important for tax purposes. And when you originally configure NetSuite, you can set the default which gets assigned to new parts as they are created.

But what if you get it wrong? It seems like it shouldn’t matter on parts that have never been sold out of inventory. And for parts that have been sold out of inventory, it’s a problem. There are related transactions that include cost, and there is no mechanism to go back and correct erroneous cost on items that have already been invoiced.

For the record, I contacted NetSuite and asked if it would be possible for them to change the costing methods on items that have never been sold out of inventory. They said that that request is currently being evaluated and at this time they intend to add that feature to some future release of NetSuite, but there is no target date for that change. So for now, the answer is no.

So let me share with you the fix which I employed. It is a snippet of SuiteTalk code.

Costing Method Fix

My code simply reads the existing item using its internal ID. As you can see in line 77, you need to set the item type of the item you’re fixing. You can write more sophisticated code that uses reflection to manipulate the item’s properties without knowing the type. Or you can simply check the type and use a CASE statement to handle multiple item types.

Once the item with the incorrect costing method is fetched, save whatever you need for the copied item. Change whatever you want in the original item, and then perform the copy. In my case, I added ” (COPIED)” to the name and modified the external ID, but did not inactivate the copied item. I had to turn off updating of fields where updating was not allowed.

Another thing you can do if your code loops through multiple items, use a TRY/CATCH block around deleting the original item. Deletes are not allowed if the original item has related transactions. If the delete fails, then inactivate.

Here is my code in a form more easily copied:

ReadResponse readResponse = service.get(
new RecordRef()
{
type = RecordType.inventoryItem
,
internalId = itemInternalId
,
typeSpecified = true
}
);

if (readResponse.status.isSuccess)
{
Console.WriteLine(“initial read was successful”);

// grab the existing record
InventoryItem item = readResponse.record as InventoryItem;

string save_itemId = item.itemId;
string save_externalId = item.externalId;

item.itemId += ” (COPIED)”;
item.externalId = Guid.NewGuid().ToString();
item.costingMethodSpecified = false;
item.createdDateSpecified = false;
item.lastModifiedDateSpecified = false;

WriteResponse updateResponse = service.update(item);

if (updateResponse.status.isSuccess)
{
item.itemId = save_itemId;
item.externalId = save_externalId;
item.costingMethod = ItemCostingMethod._fifo;
item.costingMethodSpecified = true;
item.internalId = null;
item.createdDateSpecified = false;
item.lastModifiedDateSpecified = false;

WriteResponse writeResponse = service.add(item);

if (writeResponse.status.isSuccess)
{
Console.WriteLine(“re-write of item success”);
}
else
{
Console.WriteLine(“re-write of item failed”);
foreach (StatusDetail details in writeResponse.status.statusDetail)
{
Console.WriteLine($” {details.message}”);
}
}
}
else
{
Console.WriteLine(“delete response failed”);
foreach (StatusDetail details in updateResponse.status.statusDetail)
{
Console.WriteLine($” {details.message}”);
}
}
}
else
{
Console.WriteLine(“initial read failed”);
foreach (var detail in readResponse.status.statusDetail)
{
Console.WriteLine($” {detail.message}”);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s