如何在 netsuite api 中创建日记条目?
How to create journal entry in netsuite api?
我正在尝试使用 SuiteScript 在 NetSuite 上创建日记条目 API。
这是我的代码。
export function post() {
var rec = record.create({
type: record.Type.JOURNAL_ENTRY,
isDynamic: true,
});
rec.setValue({
fieldId: "memo",
value: "from api ",
});
rec.setValue({
fieldId: "type",
value: "Journal",
});
rec.setText({
fieldId: "type",
text: "Journal",
});
rec.setValue({ fieldId: "transactionnumber", value: "158" });
rec.setValue({ fieldId: "subsidiary", value: "2" });
rec.setText({ fieldId: "subsidiary", text: "Headquarters : United States" });
rec.setValue({ fieldId: "postingperiod", value: "238" });
rec.setText({ fieldId: "postingperiod", text: "Dec 2021" });
rec.setValue({ fieldId: "customform", value: "30" });
rec.setText({ fieldId: "customform", text: "Standard Journal Entry" });
rec.setValue({ fieldId: "exchangerate", value: "1.00" });
//-------------------------debit------------------------------------------
//start a new line
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: "1",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "AcctRec",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1100 Accounts Receivable",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "",
});
//close of line
rec.commitLine({
sublistId: "line",
});
//----------------------------credit---------------------------------------
//new line again
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: "10",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "OthCurrAsset",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1200 Inventory",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "",
});
rec.commitLine({
sublistId: "line",
});
var recordId = rec.save();
//-------------------------------------------------------------------
return JSON.stringify(recordId);
}
我觉得一切正常,但我收到以下错误
{
"error": {
"code": "INVALID_FLD_VALUE",
"message": "{\"type\":\"error.SuiteScriptError\",\"name\":\"INVALID_FLD_VALUE\",\"message\":\"You have entered an Invalid Field Value 1 for the following field: account\",\"stack\":[\"anonymous(N/serverRecordService)\",\"post(/SuiteScripts/ssv2/journal_restlet.js:73)\"],\"cause\":{\"type\":\"internal error\",\"code\":\"INVALID_FLD_VALUE\",\"details\":\"You have entered an Invalid Field Value 1 for the following field: account\",\"userEvent\":null,\"stackTrace\":[\"anonymous(N/serverRecordService)\",\"post(/SuiteScripts/ssv2/journal_restlet.js:73)\"],\"notifyOff\":false},\"id\":\"\",\"notifyOff\":false,\"userFacing\":false}"
}
}
基本上这意味着我发送给创建行的帐户值 1 无效。但是 1 是现金账户的有效账户 ID。
这是我调用get方法时的行响应。
{
"line": [
{
"scheduletype": "",
"oldstartdate": "",
"entity_display": "",
"memo": "",
"residual": "",
"account_cur": "",
"amortermsrc": "",
"startdate": "",
"tax1acct": "",
"account_cur_fx": "F",
"cleareddate": "",
"custcol_adjustment_tax_code": "",
"grossamt": "",
"custcol_2663_isperson": false,
"credit": "",
"origdebit": 5000,
"item": "",
"sys_parentid": "2040634920479734",
"tax1amt": "",
"amortizationtype": "",
"entity2": "",
"custcol_emirate": "",
"enddate": "",
"entitytype": "Entity",
"lineuniquekey": "89669",
"hasimmutableamortization": false,
"taxcode": "",
"taxcode_display": "",
"custcol_2663_eft_file_format": "",
"cleared": "F",
"line": 0,
"accounttype": "AcctRec",
"kpayitem": "",
"timelineid": "",
"eliminate": false,
"custcol_adjustment_field": "",
"accounteliminate": "F",
"class_display": "",
"giftcertcode": "",
"origcredit": "",
"sys_id": "2040634962802984",
"account_display": "1100 Accounts Receivable",
"btoach": false,
"custcol_2663_lastname": "",
"debit": 5000,
"department": "",
"oldresidual": "",
"class": "",
"ritemcount": "",
"oldenddate": "",
"custcol_2663_firstname": "",
"custcol_far_trn_relatedasset": "",
"department_display": "",
"location_display": "",
"schedule": "",
"schedulenum": "",
"taxrate1": "",
"custcol_2663_companyname": "",
"location": "",
"entity_cur": "",
"account": "6",
"entity": ""
},
{
"scheduletype": "",
"oldstartdate": "",
"entity_display": "",
"memo": "",
"residual": "",
"account_cur": "",
"amortermsrc": "",
"startdate": "",
"tax1acct": "",
"account_cur_fx": "F",
"cleareddate": "",
"custcol_adjustment_tax_code": "",
"grossamt": "",
"custcol_2663_isperson": false,
"credit": 5000,
"origdebit": "",
"item": "",
"sys_parentid": "2040634920479734",
"tax1amt": "",
"amortizationtype": "",
"entity2": "",
"custcol_emirate": "",
"enddate": "",
"entitytype": "Entity",
"lineuniquekey": "89670",
"hasimmutableamortization": false,
"taxcode": "",
"taxcode_display": "",
"custcol_2663_eft_file_format": "",
"cleared": "F",
"line": 1,
"accounttype": "OthCurrAsset",
"kpayitem": "",
"timelineid": "",
"eliminate": false,
"custcol_adjustment_field": "",
"accounteliminate": "F",
"class_display": "",
"giftcertcode": "",
"origcredit": 5000,
"sys_id": "2040634962760922",
"account_display": "1200 Inventory",
"btoach": false,
"custcol_2663_lastname": "",
"debit": "",
"department": "",
"oldresidual": "",
"class": "",
"ritemcount": "",
"oldenddate": "",
"custcol_2663_firstname": "",
"custcol_far_trn_relatedasset": "",
"department_display": "",
"location_display": "",
"schedule": "",
"schedulenum": "",
"taxrate1": "",
"custcol_2663_companyname": "",
"location": "",
"entity_cur": "",
"account": "10",
"entity": ""
}
],
"recmachcustrecord109": [],
"recmachcustrecord_2663_parent_bill": [],
"recmachcustrecord_2663_parent_payment": [],
"recmachcustrecord_2663_transaction": [],
"recmachcustrecord_assetsourcetrn": [],
"recmachcustrecord_deprhistjournal": [],
"recmachcustrecord_far_expinc_transaction": [],
"recmachcustrecord_nsts_rfc_created_trans": [],
"recmachcustrecord_nsts_rfc_related_records": [],
"recmachcustrecord_summary_histjournal": [],
"recmachcustrecord_wmsse_order_no": [],
"recmachcustrecord_wmsse_order_no_clt": [],
"recmachcustrecord_wmsse_ordno": [],
"recmachcustrecord_wmsse_parent_orderno": [],
"recmachcustrecord_wmsse_ship_order": [],
"activities": [],
"mediaitem": [],
"usernotes": [],
"links": [],
"systemnotes": [],
"calls": [],
"tasks": [],
"events": []
}
这里的帐户 ID 是 6 和 10。即使我在帐户字段中使用 6 和 10,我仍然会遇到同样的错误。有谁知道如何解决这个问题?
谢谢,
奎师那
我猜它会抛出错误,因为您将帐户值作为字符串传递。
试试这个 -
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: Number(1) //Change this
});
如有任何问题,请告诉我。
您似乎在尝试使用帐户名或帐号而不是帐户内部 ID 来设置帐户。 setCurrentSublistValue
调用在处理这样的链接记录时需要内部 ID,而不是名称或编号:
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "{internalid of account}",
});
编辑:这里假设您要使用 SuiteScript 2.0,因为那是您编写的代码,而不是 SuiteTalk,后者完全是不同的代码。
问题是次要的,我的帐户 ID 不匹配。如果以后有人需要,这里是完整的代码。
export function post() {
var rec = record.create({
type: record.Type.JOURNAL_ENTRY,
isDynamic: true,
});
rec.setValue({
fieldId: "memo",
value: "from api ",
});
rec.setValue({
fieldId: "type",
value: "Journal",
});
rec.setText({
fieldId: "type",
text: "Journal",
});
// rec.setValue({ fieldId: "transactionnumber", value: "158" });
rec.setValue({ fieldId: "subsidiary", value: "2" });
rec.setText({ fieldId: "subsidiary", text: "Headquarters : United States" });
rec.setValue({ fieldId: "postingperiod", value: "238" });
rec.setText({ fieldId: "postingperiod", text: "Dec 2021" });
rec.setValue({ fieldId: "trandate", value: new Date("12/27/2021") });
// rec.setValue({ fieldId: "customform", value: "30" });
// rec.setText({ fieldId: "customform", text: "Standard Journal Entry" });
rec.setValue({ fieldId: "exchangerate", value: "1.00" });
//-------------------------debit------------------------------------------
//start a new line
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: 363,
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "AcctRec",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1100 Accounts Receivable",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "",
});
//close of line
rec.commitLine({
sublistId: "line",
});
//----------------------------credit---------------------------------------
//new line again
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: 10,
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "OthCurrAsset",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1200 Inventory",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "",
});
rec.commitLine({
sublistId: "line",
});
var recordId = rec.save();
//-------------------------------------------------------------------
return JSON.stringify(recordId);
}
我正在尝试使用 SuiteScript 在 NetSuite 上创建日记条目 API。
这是我的代码。
export function post() {
var rec = record.create({
type: record.Type.JOURNAL_ENTRY,
isDynamic: true,
});
rec.setValue({
fieldId: "memo",
value: "from api ",
});
rec.setValue({
fieldId: "type",
value: "Journal",
});
rec.setText({
fieldId: "type",
text: "Journal",
});
rec.setValue({ fieldId: "transactionnumber", value: "158" });
rec.setValue({ fieldId: "subsidiary", value: "2" });
rec.setText({ fieldId: "subsidiary", text: "Headquarters : United States" });
rec.setValue({ fieldId: "postingperiod", value: "238" });
rec.setText({ fieldId: "postingperiod", text: "Dec 2021" });
rec.setValue({ fieldId: "customform", value: "30" });
rec.setText({ fieldId: "customform", text: "Standard Journal Entry" });
rec.setValue({ fieldId: "exchangerate", value: "1.00" });
//-------------------------debit------------------------------------------
//start a new line
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: "1",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "AcctRec",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1100 Accounts Receivable",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "",
});
//close of line
rec.commitLine({
sublistId: "line",
});
//----------------------------credit---------------------------------------
//new line again
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: "10",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "OthCurrAsset",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1200 Inventory",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "",
});
rec.commitLine({
sublistId: "line",
});
var recordId = rec.save();
//-------------------------------------------------------------------
return JSON.stringify(recordId);
}
我觉得一切正常,但我收到以下错误
{
"error": {
"code": "INVALID_FLD_VALUE",
"message": "{\"type\":\"error.SuiteScriptError\",\"name\":\"INVALID_FLD_VALUE\",\"message\":\"You have entered an Invalid Field Value 1 for the following field: account\",\"stack\":[\"anonymous(N/serverRecordService)\",\"post(/SuiteScripts/ssv2/journal_restlet.js:73)\"],\"cause\":{\"type\":\"internal error\",\"code\":\"INVALID_FLD_VALUE\",\"details\":\"You have entered an Invalid Field Value 1 for the following field: account\",\"userEvent\":null,\"stackTrace\":[\"anonymous(N/serverRecordService)\",\"post(/SuiteScripts/ssv2/journal_restlet.js:73)\"],\"notifyOff\":false},\"id\":\"\",\"notifyOff\":false,\"userFacing\":false}"
}
}
基本上这意味着我发送给创建行的帐户值 1 无效。但是 1 是现金账户的有效账户 ID。
这是我调用get方法时的行响应。
{
"line": [
{
"scheduletype": "",
"oldstartdate": "",
"entity_display": "",
"memo": "",
"residual": "",
"account_cur": "",
"amortermsrc": "",
"startdate": "",
"tax1acct": "",
"account_cur_fx": "F",
"cleareddate": "",
"custcol_adjustment_tax_code": "",
"grossamt": "",
"custcol_2663_isperson": false,
"credit": "",
"origdebit": 5000,
"item": "",
"sys_parentid": "2040634920479734",
"tax1amt": "",
"amortizationtype": "",
"entity2": "",
"custcol_emirate": "",
"enddate": "",
"entitytype": "Entity",
"lineuniquekey": "89669",
"hasimmutableamortization": false,
"taxcode": "",
"taxcode_display": "",
"custcol_2663_eft_file_format": "",
"cleared": "F",
"line": 0,
"accounttype": "AcctRec",
"kpayitem": "",
"timelineid": "",
"eliminate": false,
"custcol_adjustment_field": "",
"accounteliminate": "F",
"class_display": "",
"giftcertcode": "",
"origcredit": "",
"sys_id": "2040634962802984",
"account_display": "1100 Accounts Receivable",
"btoach": false,
"custcol_2663_lastname": "",
"debit": 5000,
"department": "",
"oldresidual": "",
"class": "",
"ritemcount": "",
"oldenddate": "",
"custcol_2663_firstname": "",
"custcol_far_trn_relatedasset": "",
"department_display": "",
"location_display": "",
"schedule": "",
"schedulenum": "",
"taxrate1": "",
"custcol_2663_companyname": "",
"location": "",
"entity_cur": "",
"account": "6",
"entity": ""
},
{
"scheduletype": "",
"oldstartdate": "",
"entity_display": "",
"memo": "",
"residual": "",
"account_cur": "",
"amortermsrc": "",
"startdate": "",
"tax1acct": "",
"account_cur_fx": "F",
"cleareddate": "",
"custcol_adjustment_tax_code": "",
"grossamt": "",
"custcol_2663_isperson": false,
"credit": 5000,
"origdebit": "",
"item": "",
"sys_parentid": "2040634920479734",
"tax1amt": "",
"amortizationtype": "",
"entity2": "",
"custcol_emirate": "",
"enddate": "",
"entitytype": "Entity",
"lineuniquekey": "89670",
"hasimmutableamortization": false,
"taxcode": "",
"taxcode_display": "",
"custcol_2663_eft_file_format": "",
"cleared": "F",
"line": 1,
"accounttype": "OthCurrAsset",
"kpayitem": "",
"timelineid": "",
"eliminate": false,
"custcol_adjustment_field": "",
"accounteliminate": "F",
"class_display": "",
"giftcertcode": "",
"origcredit": 5000,
"sys_id": "2040634962760922",
"account_display": "1200 Inventory",
"btoach": false,
"custcol_2663_lastname": "",
"debit": "",
"department": "",
"oldresidual": "",
"class": "",
"ritemcount": "",
"oldenddate": "",
"custcol_2663_firstname": "",
"custcol_far_trn_relatedasset": "",
"department_display": "",
"location_display": "",
"schedule": "",
"schedulenum": "",
"taxrate1": "",
"custcol_2663_companyname": "",
"location": "",
"entity_cur": "",
"account": "10",
"entity": ""
}
],
"recmachcustrecord109": [],
"recmachcustrecord_2663_parent_bill": [],
"recmachcustrecord_2663_parent_payment": [],
"recmachcustrecord_2663_transaction": [],
"recmachcustrecord_assetsourcetrn": [],
"recmachcustrecord_deprhistjournal": [],
"recmachcustrecord_far_expinc_transaction": [],
"recmachcustrecord_nsts_rfc_created_trans": [],
"recmachcustrecord_nsts_rfc_related_records": [],
"recmachcustrecord_summary_histjournal": [],
"recmachcustrecord_wmsse_order_no": [],
"recmachcustrecord_wmsse_order_no_clt": [],
"recmachcustrecord_wmsse_ordno": [],
"recmachcustrecord_wmsse_parent_orderno": [],
"recmachcustrecord_wmsse_ship_order": [],
"activities": [],
"mediaitem": [],
"usernotes": [],
"links": [],
"systemnotes": [],
"calls": [],
"tasks": [],
"events": []
}
这里的帐户 ID 是 6 和 10。即使我在帐户字段中使用 6 和 10,我仍然会遇到同样的错误。有谁知道如何解决这个问题?
谢谢, 奎师那
我猜它会抛出错误,因为您将帐户值作为字符串传递。
试试这个 -
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: Number(1) //Change this
});
如有任何问题,请告诉我。
您似乎在尝试使用帐户名或帐号而不是帐户内部 ID 来设置帐户。 setCurrentSublistValue
调用在处理这样的链接记录时需要内部 ID,而不是名称或编号:
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "{internalid of account}",
});
编辑:这里假设您要使用 SuiteScript 2.0,因为那是您编写的代码,而不是 SuiteTalk,后者完全是不同的代码。
问题是次要的,我的帐户 ID 不匹配。如果以后有人需要,这里是完整的代码。
export function post() {
var rec = record.create({
type: record.Type.JOURNAL_ENTRY,
isDynamic: true,
});
rec.setValue({
fieldId: "memo",
value: "from api ",
});
rec.setValue({
fieldId: "type",
value: "Journal",
});
rec.setText({
fieldId: "type",
text: "Journal",
});
// rec.setValue({ fieldId: "transactionnumber", value: "158" });
rec.setValue({ fieldId: "subsidiary", value: "2" });
rec.setText({ fieldId: "subsidiary", text: "Headquarters : United States" });
rec.setValue({ fieldId: "postingperiod", value: "238" });
rec.setText({ fieldId: "postingperiod", text: "Dec 2021" });
rec.setValue({ fieldId: "trandate", value: new Date("12/27/2021") });
// rec.setValue({ fieldId: "customform", value: "30" });
// rec.setText({ fieldId: "customform", text: "Standard Journal Entry" });
rec.setValue({ fieldId: "exchangerate", value: "1.00" });
//-------------------------debit------------------------------------------
//start a new line
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: 363,
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "AcctRec",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1100 Accounts Receivable",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "",
});
//close of line
rec.commitLine({
sublistId: "line",
});
//----------------------------credit---------------------------------------
//new line again
rec.selectNewLine({
sublistId: "line",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account",
value: 10,
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "accounttype",
value: "OthCurrAsset",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "account_display",
value: "1200 Inventory",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "credit",
value: "200",
});
rec.setCurrentSublistValue({
sublistId: "line",
fieldId: "debit",
value: "",
});
rec.commitLine({
sublistId: "line",
});
var recordId = rec.save();
//-------------------------------------------------------------------
return JSON.stringify(recordId);
}