0
votes

I have written a script which creates a billing schedule record for items on the creation of sales order using afterSubmit() user event script. The billing schedule record gets created for every item,but it also should be set in line level field 'billing schedule' of the sales order.details in This is the field marked where i need billing schedule to setattachment

var rec =nlapiCreateRecord('billingschedule');

            var res = itemname.substring(0, 40);
            rec.setFieldValue('name',res);
            rec.setFieldValue('initialamount',itemamount);
            rec.setFieldValue('numberremaining','5');
            rec.setFieldText('frequency','Daily');

                                var sub = nlapiSubmitRecord(rec,true);
                                if(sub!=null)
                                    {
                                        nlapiSetLineItemValue('item','billingschedule',i+1,sub);
                                    }
1

1 Answers

0
votes

You need to load the record in afterSubmit, otherwise it's read-only.

var salesOrderId = nlapiGetRecordId();
var soRec = nlapiLoadRecord('salesorder', salesOrderId);
// DO YOUR BILLING SCHEDULE CREATION LINE WORK
var soLines = soRec.getLineItemCount('item');
// SS1 indexes start at 1
for (var x = 1; x <= soLines; x++) {
    var rec =nlapiCreateRecord('billingschedule');  
    var res = itemname.substring(0, 40);
    rec.setFieldValue('name',res);
    rec.setFieldValue('initialamount',itemamount);
    rec.setFieldValue('numberremaining','5');
    rec.setFieldText('frequency','Daily');
    var sub = nlapiSubmitRecord(rec,true);
    if(sub!=null) {
        soRec.setLineItemValue('item','billingschedule', x, sub);
    }
}
// Submit the record to save the values
 nlapiSubmitRecord(soRec);