You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite采购订单UE脚本按钮:prompt输入值无法通过submitFields保存求助

NetSuite: submitFields Not Updating Custom Body Field After Prompt Input

I added a custom button to Purchase Orders via a User Event (UE) script. When clicked, it pops up a prompt to let users enter text, and after clicking "OK", that text should save to a custom body field custbody_reasonof_rejection. I tried using submitFields but it's not working at all—hoping someone can help troubleshoot this!

User Event Script Code

context.form.addButton({ 
  id: 'custpage_reject', 
  label: 'Reject With Reason', 
  functionName: 'rejectButton()' 
})
context.form.clientScriptModulePath = 'SuiteScripts/mx_rejectionReason_cs.js';

Client Script Function

function rejectButton() {
 rejectReasonValue = window.prompt("Reason for Rejection ?");
 console.log('prompt:', rejectReasonValue)
 nsCurrentRecord.submitFields({
 type: recType,
 id: recId,
 values: { custbody_reasonof_rejection: rejectReasonValue, },
 options: { enableSourcing: true, ignoreMandatoryFields: true }
 });
}

Looking at your code, there are a few critical issues that are almost certainly causing the submitFields call to fail:

  1. Undefined core variables: Your client script doesn’t define recType, recId, or nsCurrentRecord. These are required to target the correct record and use the NetSuite API properly.
  2. Missing module loading: Client-side SuiteScripts need to load NetSuite modules (like N/currentRecord) using AMD-style syntax to access record functionality.
  3. Unhandled prompt cancellation: If the user clicks "Cancel" on the prompt, rejectReasonValue becomes null—this could lead to unexpected behavior or failed API calls.

Fixed Client Script

// Load the required NetSuite currentRecord module
define(['N/currentRecord'], function(currentRecord) {
  function rejectButton() {
    // Get the active purchase order record instance
    var currentPO = currentRecord.get();
    var rejectReasonValue = window.prompt("Reason for Rejection ?");
    
    // Exit early if user cancels the prompt
    if (rejectReasonValue === null) return;

    console.log('Prompt input:', rejectReasonValue);
    
    // Submit the field update directly on the current record
    currentPO.submitFields({
      values: { 
        custbody_reasonof_rejection: rejectReasonValue 
      },
      options: { 
        enableSourcing: true, 
        ignoreMandatoryFields: true 
      }
    });
    
    // Optional: Refresh the page to show the updated field immediately
    window.location.reload();
  }
  
  // Expose the function so the UE script's button can call it
  return {
    rejectButton: rejectButton
  };
});

Key Fixes & Notes

  • Used define() to properly load the N/currentRecord module (standard practice for NetSuite client scripts).
  • Fetched the current record with currentRecord.get(), which lets us call submitFields directly without needing to pass type and id separately.
  • Added a check to exit if the user cancels the prompt, avoiding unnecessary API calls.
  • Included an optional page reload to refresh the UI so the updated field value is visible right away (you can remove this if immediate visual feedback isn’t needed).

Also, double-check these details to rule out other issues:

  • Confirm the custom field ID custbody_reasonof_rejection is exactly correct (NetSuite field IDs are case-sensitive).
  • Ensure the user’s role has edit permissions for both the Purchase Order record and the custbody_reasonof_rejection field.

内容的提问来源于stack exchange,提问作者4N335

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:52:40