Create an item receipt from a purchase order

This sample is a custom module script that creates an item receipt from a purchase order. This is either a custom module or an individual function within a user event or other server script, so no JSDoc or define statement or return statement or entry point function is needed. But you will need to load the N/record and N/email modules for the function to work.

The conversion of this script from SuiteScript 1.0 to SuiteScript 2.1 includes the following:

SuiteScript 1.0 Script

SuiteScript 2.1 Script

                    function transformPurchaseOrder() {
   var fromRecord;
   var fromId;
   var toRecord;
   var trecord;
   var qty;

   fromRecord = 'purchaseorder';
   fromId = 26;
   toRecord = 'itemreceipt';

   trecord = nlapiTransformRecord(fromrecord, fromid, torecord);
   qty = trecord.getLineItemValue('item', 'quantity', 1 );
   trecord.setLineItemValue('item', 'quantity', 1, '2' );
   var idl = nlapiSubmitRecord(trecord, true);

   nlapiSendEmail(-5, -5, 'Transform Email' + 'Original Qty = ' + qty + ' ' + 'Record Created = ' + idl , null);
} 

                  
                    function transformPurchaseOrder() {
    const fromRecord = 'purchaseorder';
    const fromId = 26;
    const toRecord = 'itemreceipt';

    const trecord = record.transform({
        fromType: fromRecord,
        fromId: fromId,
        toType: toRecord,
    });

    const qty = trecord.getSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        line: 1
    });

    trecord.setSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        line: 1,
        value: '2'
    });
    
    const idl = trecord.save({
        enableSourcing: true
    });

    email.send({
        author: -5,
        recipients: -5,
        subject: 'Transform Email' + 'Original Qty = ' + qty + ' ' + 'Record Created = ' + idl,
        body: null,
    });
} 

                  

General Notices