NetSuite - Suitescript 1.0

1.6k Views Asked by At

how to set fields on customer record in before Load event , on before submit event and on after submit event? i am trying to create a message record and check this code.

if (type == 'create')
    {
        var custRecord = nlapiGetNewRecord();
        
        if(custRecord.getFieldValue('salesrep') != null)
        {
            var message = nlapiCreateRecord("message");
            
            message.setFieldValue('entity');
            
            message.setFieldValue('message');
            
            custRecord.getFieldValue('salesrep');
            
            var today = new Date();
            var tomorrow = nlapiAddDays(today, 1);
            message.setFieldValue('startdate', nlapiDateToString(tomorrow));
            
            message.setFieldValue('message',custRecord.getFieldValue('message'));
            
            
            try
            {
                var callId = nlapiSubmitRecord(message, true);
                nlapiLogExecution('DEBUG', 'message record created successfully', 'ID = ' + messageId);
            }
            catch (e)
            {
                nlapiLogExecution('ERROR', e.getcode(), e.getDetails());
            }
        }
        
    }

why don't i get the message field in my customer record?

2

There are 2 best solutions below

0
On

I don't realy understand what you want to do :). you set fields with empty values.... anyway to create a messege in NS1.0. you need this :

var message = nlapiCreateRecord("message");

/** mandatory fields */
message.setFieldValue('subject', "message title");
message.setFieldValue('message', "message body");
/** /mandatory fields */

/** attach the msg to a record, transaction */

/** customers, prospects, etc */
message.setFieldValue('entity', "entityInternalID"); 

/** sales orders, invoices, etc */
message.setFieldValue('transaction', "transactionInternalID");

/** cases */
message.setFieldValue('activity', "caseInternalId");

/** /attach the msg to a record, transaction */

/** save the msg */
var msgId = nlapiSubmitRecord(message, true);
2
On

First, let us know what kind of script you are creating? Is it a userevent or client script? Anyway, since you have mentioned that you want it to run in 3 specific context I'm assuming it is a userevent script. I highly discouraged using 1.0 if you're developing a Netsuite script. It will be unsupported soon and will become obsolete. Here's a detailed example on how to create userevent script https://netsuite.custhelp.com/app/answers/detail/a_id/51660/kw/Creating%20a%20user%20event%20script