Transform a salesrecord to invoice through script

Im trying to transform salesorder record to invoice,but Im getting Invalid Initilize error and invalid refernce.but I have given form Id as internalId y Im getting this error can Any one help me
function saveRecord(context) {
        var objRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId:22367,
            toType: record.Type.INVOICE,
            isDynamic: true,
        });
    }
Rookie Asked on September 17, 2021 in SuiteScript.
Add Comment
4 Answer(s)

Need to share more informatiion, like the exact error message and code. From your code, the only thing that can be guess is is that you got the internal id of the sales order wrong. Potentially you are trying to transform a sales order that cannot  be transformed into an invoice.

Intermediate Answered on September 17, 2021.
Add Comment

We attempted this method to link a vendor to a customer and could not get it to work.

We worked around the issue by first creating a brand new customer and then using the entity deduplication task to merge the vendor and customer records.

Rookie Answered on September 21, 2021.
Add Comment
            let customerRecord = record.create({type: record.Type.CUSTOMER});
            customerRecord.setValue('companyname', vendorRecord.getValue('companyname'));
            customerRecord.setValue('subsidiary', vendorRecord.getValue('subsidiary'));
            customerRecord.setValue('status', 13);
            customerID = customerRecord.save();
            log.debug('customer creation', customerID);
            let customerLinkTask = task.create({taskType: task.TaskType.ENTITY_DEDUPLICATION});
            customerLinkTask.entityType = task.DedupeEntityType.CUSTOMER;
            customerLinkTask.dedupeMode = task.DedupeMode.MERGE;
            customerLinkTask.masterSelectionMode = task.MasterSelectionMode.SELECT_BY_ID;
            customerLinkTask.masterRecordId = vendorID;
            customerLinkTask.recordIds = [customerID];
            let customerLinkTaskId = customerLinkTask.submit();
            log.debug('created customer link task ', customerLinkTaskId);
 
Rookie Answered on September 21, 2021.
Add Comment
In the above code I had done mistake,that is I did’nt save the record that is the reason the salesorder is not transform to Invoice now its working fine.
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
 define([“N/log”, “N/email”, “N/record”], function(log, email, record) {
    function afterSubmit(scriptContext) {
        var newOrderId = scriptContext.newRecord.id;
        var objRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId: newOrderId,
            toType: record.Type.INVOICE,
            isDynamic: true
        });
       // Add additional code.
var recordId = objRecord.save({
    enableSourcing: true,
    ignoreMandatoryFields: true
});
// Add additional code.
    }
    return {
        afterSubmit: afterSubmit
    }
});
we can see changes in releated recods subtab,the inovice is created.
Rookie Answered on September 22, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor