does anyone have an idea why I'd be getting this e...
# suitescript
k
does anyone have an idea why I'd be getting this error
Items you have requested in the record have been deleted since you retrieved the form
when trying to create an Inventory Adjustment record? Such a vague error 😕 Here's the code (please excuse all the magic values, it has a very specific use case):
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */

import { EntryPoints } from 'N/types';
import * as log from 'N/log';
import * as ui from 'N/ui/serverWidget';
import * as record from 'N/record';

export const onRequest: EntryPoints.Suitelet.onRequest = (scriptContext: EntryPoints.Suitelet.onRequestContext) => {
    if (scriptContext.request.method === 'GET') {
        // render the form

        const form = ui.createForm({
            title: 'Enter Catalog Request Amount'
        });
    
        form.addField({
            id: 'catalog_quantity',
            type: ui.FieldType.INTEGER,
            label: 'Catalog Quantity'
        });
    
        form.addSubmitButton({
            label: 'Submit Quantity'
        });
    
        scriptContext.response.writePage(form);
    } else {
        // === submission of form, use field ids given
        // as request parameters to create inventory adjustment record

        const catalogQuantity = scriptContext.request.parameters.catalog_quantity;

        if (catalogQuantity) {
            const adjustmentRecord = record.create({
                type: record.Type.INVENTORY_ADJUSTMENT,
                isDynamic: false
            });

            // default custom form
            adjustmentRecord.setValue({
                fieldId: 'customform',
                value: 10
            });

            adjustmentRecord.setValue({
                fieldId: 'trandate',
                value: new Date()
            });
    
            adjustmentRecord.setValue({
                fieldId: 'subsidiary',
                value: 1
            });
    
            adjustmentRecord.setValue({
                fieldId: 'account',
                value: 1242	
            });

            adjustmentRecord.insertLine({
                sublistId: 'inventory',
                line: 0
            });
    
            adjustmentRecord.setSublistValue({
                sublistId: 'inventory',
                fieldId: 'item',
                value: 276221,
                line: 0
            });
    
            adjustmentRecord.setSublistValue({
                sublistId: 'inventory',
                fieldId: 'location',
                value: 2,
                line: 0
            });
    
            adjustmentRecord.setSublistValue({
                sublistId: 'inventory',
                fieldId: 'adjustqtyby',
                value: catalogQuantity,
                line: 0
            });

            const inventoryDetailSubrecord = adjustmentRecord.getSublistSubrecord({
                sublistId: 'inventory',
                fieldId: 'inventorydetail',
                line: 0
            });

            inventoryDetailSubrecord.insertLine({
                sublistId: 'inventoryassignment',
                line: 0
            });

            inventoryDetailSubrecord.setSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'issueinventorynumber',
                value: 803,
                line: 0
            });

            inventoryDetailSubrecord.setSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'quantity',
                value: catalogQuantity,
                line: 0
            });

            adjustmentRecord.save();
        }
    }
}
b
Id check to make sure all the accounts are set
Especially on the item
k
Hmm, I don't see that account under the Accounting tab on the item - but I was able to create the record via the UI using that item and account combo
b
Sometimes the ui defaults values for an account while a script will not
And you get weird errors when you try to replicate it in script
Id set all the different accounts on the item and retry your script
k
Hmm I still get the same error after trying this - I changed the COGS account on the item record to match the account set on the inventory adjustment record script
Ah okay, I figured it out - I was using the wrong fieldId for
binnumber
. Thank you for your help!