Convert an Opportunity Using SuiteScript

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/log'], function(record, log) {
    function afterSubmit(context) {
        if (context.type !== context.UserEventType.CREATE) return;


        try {
            var opportunityId = context.newRecord.id;
            
            var estimate = record.transform({
                fromType: record.Type.OPPORTUNITY,
                fromId: opportunityId,
                toType: record.Type.ESTIMATE,
                isDynamic: true
            });


            var estimateId = estimate.save();
            log.debug('Estimate Created', 'ID: ' + estimateId);
        } catch (e) {
            log.error('Error Converting Opportunity', e);
        }
    }
    return {
        afterSubmit: afterSubmit
    };
});

Leave a comment

Your email address will not be published. Required fields are marked *