hey all, I am creating a custom record as part of ...
# suitescript
n
hey all, I am creating a custom record as part of a beforeSubmit (on a time entry) and I want to link the created custom record to a field on the time entry -> using setValue the custom record value is getting set on the field but when I check after the field is blank.. any ideas?
b
what does your code look like
n
so i think I need to conver to afterSubmit
Copy code
/*******************************************************************
 *
 *
 * Name: CERT_SUE_TIME_CUS_REC.js
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * Version: 0.0.1
 *
 *
 * Author: Nicolas Bean
 * Purpose: Creates a custom record from any time entry
 * Script: The script record id
 * Deploy: The script deployment record id
 *
 *
 * ******************************************************************* */

define(['N/record', 'N/search', 'N/log'],
  function(record, search, log) {
    function beforeSubmit(context) {
      var oldtimerec = context.oldRecord;
      log.debug('oldtimerec', oldtimerec);
      var timerec = context.newRecord;
      log.debug('timerec', timerec);
      var cusrec = '';
      log.debug('cusrec', cusrec);

      try {

        var timeid = timerec.id;
        log.debug('timeid', timeid);
        var timecus = timerec.getValue({
          fieldId: 'customer'
        });
        log.debug('timecus', timecus);
        var timeemployee = timerec.getValue({
          fieldId: 'employee'
        });
        log.debug('timeemployee', timeemployee);
        var timedate = timerec.getValue({
          fieldId: 'trandate'
        });
        log.debug('timedate', timedate);
        var timeduration = timerec.getValue({
          fieldId: 'hours'
        });
        log.debug('timeduration', timeduration);
        var timeitem = timerec.getValue({
          fieldId: 'item'
        });
        log.debug('timeitem', timeitem);
        var timesubmission = timerec.getValue({
          fieldId: 'custcol_submission_number'
        });
        log.debug('timesubmission', timesubmission);

        // If the context is create
        if (context.UserEventType.CREATE) {
          var newcusrec = record.create({
            type: 'customrecord_internal_time_tickets'
          });
          newcusrec.setValue({
            fieldId: 'custrecord_project_internal',
            value: timecus
          }).setValue({
            fieldId: 'custrecord_time_entry',
            value: timeid
          }).setValue({
            fieldId: 'custrecord_employee',
            value: timeemployee
          }).setValue({
            fieldId: 'custrecord_date_internal_time',
            value: timedate
          }).setValue({
            fieldId: 'custrecord_duration',
            value: timeduration
          }).setValue({
            fieldId: 'custrecord_submission_number_internal',
            value: timesubmission
          }).setValue({
            fieldId: 'custrecord_service_item',
            value: timeitem
          });
          var tempcusrec = newcusrec.save();
          log.debug('tempcusrec', tempcusrec);
          var setcustomrec = timerec.setValue({
            fieldId: 'custcol_custom_record_link',
            value: tempcusrec
          });
          log.debug('setcustomrec', setcustomrec);
        } else {
          var cusrec = oldtimerec.getValue({
            fieldId: 'custcol_custom_record_link'
          });
          timerec.save();
          record.submitFields({
            type: 'customrecord_internal_time_tickets',
            id: cusrec,
            values: {
              custrecord_project_internal: timecus,
              custrecord_time_entry: timeid,
              custrecord_employee: timeemployee,
              custrecord_date_internal_time: timedate,
              custrecord_duration: timeduration,
              custrecord_submission_number_internal: timesubmission,
              custrecord_service_item: timeitem
            }
          });
        }

      } catch (e) {
        log.debug('Error reads: ', e.name + e.message);
      }
    }

    function afterSubmit(contex) {
      var timerec = context.newRecord;
      var oldtimerec = contex.oldRecord;

      try {
        var timeid = timerec.id;
        log.debug('timeid', timeid);

        if (context.UserEventType.CREATE) {

        }

      } catch (e) {
        log.debug('Error reads: ', e.name + e.message);
      }
    }

    return {
      beforeSubmit: beforeSubmit
    };
  });
i just started with afterSubmit