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:
- Undefined core variables: Your client script doesn’t define
recType,recId, ornsCurrentRecord. These are required to target the correct record and use the NetSuite API properly. - Missing module loading: Client-side SuiteScripts need to load NetSuite modules (like
N/currentRecord) using AMD-style syntax to access record functionality. - Unhandled prompt cancellation: If the user clicks "Cancel" on the prompt,
rejectReasonValuebecomesnull—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 theN/currentRecordmodule (standard practice for NetSuite client scripts). - Fetched the current record with
currentRecord.get(), which lets us callsubmitFieldsdirectly without needing to passtypeandidseparately. - 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_rejectionis 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_rejectionfield.
内容的提问来源于stack exchange,提问作者4N335
相关产品推荐
相关产品推荐

