我有自定义记录,我必须将状态值设置为已批准。我使用了record.setValue,它在日志中发生变化,但在记录中没有变化

问题描述 投票:0回答:2

var currentStatus = reversalRecord.getValue({ 字段 ID: '状态' }); log.debug('设置前当前状态:', currentStatus);

                reversalRecord.setValue({
                    fieldId: 'status',
                    value: "Approved"
                }); 

                // Log status after setting
                var newStatus = reversalRecord.getValue({
                    fieldId: 'status'
                });
                log.debug('New Status after Set:', newStatus);

请帮我解决这个问题

netsuite user-event
2个回答
0
投票

如果您要保存的是日记帐分录,则需要将字段“已批准”设置为

true


0
投票

在 NetSuite SuiteScript 2.0 中,如果您使用 record.setValue 更新自定义记录中的字段,您还需要使用 record.save() 方法提交更改,以将更改保存到数据库中。

/**

  • @NApi版本2.x

  • @NScriptType Suitelet */ 定义(['N /记录','N /日志'],函数(记录,日志){

    函数 onRequest(context) { 尝试 { // 将 'customrecord_your_custom_record_id' 替换为自定义记录类型的实际内部 ID var customRecordId = 'customrecord_your_custom_record_id';

         // Replace 'your_custom_record_field_id' with the actual internal ID of the 'status' field in your custom record
         var statusFieldId = 'your_custom_record_field_id';
    
         // Replace 'your_custom_record_id' with the actual internal ID of the specific record you want to update
         var customRecordInstance = record.load({
             type: customRecordId,
             id: 'your_custom_record_id',
             isDynamic: true,
         });
    
         // Set the 'status' field value to 'approved'
         customRecordInstance.setValue({
             fieldId: statusFieldId,
             value: 'approved',
         });
    
         // Save the changes to the custom record
         var recordId = customRecordInstance.save();
    
         log.debug({
             title: 'Record Updated',
             details: 'Custom Record ID: ' + recordId,
         });
    
         context.response.write('Record Updated Successfully');
     } catch (e) {
         log.error({
             title: 'Error',
             details: e.toString(),
         });
    
         context.response.write('Error updating record: ' + e.message);
     }
    

    }

    返回{ onRequest: onRequest, }; });

© www.soinside.com 2019 - 2024. All rights reserved.