最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Netsuite Script beforeLoad record not being modified - Stack Overflow

programmeradmin0浏览0评论

I trying to modify a Purchase Order when a user opens it. This seems like this is a really simple example but doesn't seem to work. In the GUI I don't see the "test" memo. And in the script debug the memo field is empty.

I know the script is running because of the debug.

/**
 * Update Drop Ship PO with route Information
 *
 * @author Patrick 
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */


define(['N/search', 'N/record'],

    function(search, record) {
        function beforeLoad(context) {
            var newRecord = context.newRecord;
            newRecord.setValue({fieldId: 'memo', value: 'this is a test'});
            log.debug({title: 'memo', details: newRecord.getValue({fieldId: 'memo'})});

            return true;
        }
      return {
        beforeLoad: beforeLoad
    };
});

I am assuming it has something to do with the record I can modify but I can't for the life of me find a working example in the docs. Any help would be greatly appreciated.

I trying to modify a Purchase Order when a user opens it. This seems like this is a really simple example but doesn't seem to work. In the GUI I don't see the "test" memo. And in the script debug the memo field is empty.

I know the script is running because of the debug.

/**
 * Update Drop Ship PO with route Information
 *
 * @author Patrick 
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */


define(['N/search', 'N/record'],

    function(search, record) {
        function beforeLoad(context) {
            var newRecord = context.newRecord;
            newRecord.setValue({fieldId: 'memo', value: 'this is a test'});
            log.debug({title: 'memo', details: newRecord.getValue({fieldId: 'memo'})});

            return true;
        }
      return {
        beforeLoad: beforeLoad
    };
});

I am assuming it has something to do with the record I can modify but I can't for the life of me find a working example in the docs. Any help would be greatly appreciated.

Share Improve this question edited May 14, 2019 at 22:00 Patrick_Finucane asked May 14, 2019 at 21:38 Patrick_FinucanePatrick_Finucane 7551 gold badge7 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You cannot modify fields on existing records in beforeLoad; see the Help page for beforeLoad for details. Here's a snippet of beforeLoad limitations:

  • beforeLoad user events cannot be triggered when you load/access an online form.
  • Data cannot be manipulated for records that are loaded in beforeLoad scripts. If you attempt to update a record loaded in beforeLoad, the logic is ignored.
  • Data can be manipulated for records created in beforeLoad user events.
  • Attaching a child custom record to its parent or detaching a child custom record from its parent triggers an edit event.

The second bullet point is the relevant one for your issue.

newRecord.setValue wont work in beforeLoad. Its better if you use newRecord.submitFields like below

record.submitFields({
    id: newRecord.id,
    type: newRecord.type,
    values: {'memo': 'this is a test'}
});

Hope it helps!!

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>