In a Map Reduce script, why am I getting the error...
# suitescript
k
In a Map Reduce script, why am I getting the error
Cannot find function setCurrentSublistValue in object standard record.","stack":["createError(N/error)"],"cause":{"message":"Cannot find function setCurrentSublistValue in object standard record.
The relevant code is below. I am trying to simply copy the lines from an Invoice -> New Opportunity record.
Copy code
log.debug({
                title: 'Begin Create Opportunity',
                details: '.'
            }); 
            var params = {};
            params.inactiveItem = '';
            log.debug({
                title: 'params',
                details: JSON.stringify(params)
            });
            log.debug({
                title: 'create opportunity',
                details: JSON.stringify(opportunityData)
            });
            var invoice = record.load({
                type: record.Type.INVOICE,
                id: invoiceIdee,
                isDynamic: true
            });

            var totalLines = invoice.getLineCount("item");
            
            var rec = record.create({
                type: record.Type.OPPORTUNITY
            });

            rec.setValue('title', opportunityData.opportunityname);
            rec.setValue('entity', opportunityData.customerid);
            rec.setValue('memo', opportunityData.memo);
            rec.setValue('custbodyend_customer', opportunityData.endCustomer ? opportunityData.endCustomer : '');
            rec.setValue(CUSTOM_FIELDS.BUSINESS_TYPE, 3);

            if (!isNullOrEmpty(opportunityData.expectedCloseDate)) {
                rec.setValue('expectedclosedate', opportunityData.expectedCloseDate);
            }

            for (var ii = 0; ii < totalLines; ii++) {
                rec.insertLine({
                    sublistId: 'item',
                    line: ii,
                });

                // var isInactive = opportunityData.lineItem[ii].isInactive == 'T' || '';
                // var displayName = opportunityData.lineItem[ii].itemDisplayName || '';
                var isInactive = '';
                var displayName = '';

                if (!isNullOrEmpty(isInactive) && !isNullOrEmpty(params.inactiveItem)) {
                    rec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: params.inactiveItem
                    });
                    rec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'description',
                        value: displayName
                    });
                } else {
                    rec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: opportunityData.lineItem[ii].item
                    });
                }

                rec.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'quantity',
                    value: opportunityData.lineItem[ii].quantity
                });
                // rec.setCurrentSublistValue('item', CUSTOM_COLUMNS.START_DATE, opportunityData.lines[ii].startDate || '');
                // rec.setCurrentSublistValue('item', CUSTOM_COLUMNS.END_DATE, opportunityData.lines[ii].endDate || '');
                rec.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: CUSTOM_COLUMNS.SERIAL,
                    value: opportunityData.lineItem[ii].serial
                });
                rec.commitLine({
                    sublistId: 'item'
                });
            }
m
setCurrentSublistValue
is only available when the record is in dynamic mode. You will need to add
isDynamic: true
to the record.create.
k
will try that, didnt think you needed it when creating a record. Thanks!
s
don't use dynamic mode apis
k
k
m
I would revise that to say don't use them unless you have a specific reason to use them.