使用Suitescript,我可以在没有N/search的情况下找到与我当前相关的记录吗?
Using Suitescript, can I find a record related to my current without N/search?
我正在尝试删除与使用工作流操作脚本加载的当前记录相关的记录。我看过类似问题的其他答案,说我可以通过使用关键字段中的值作为搜索参数进行搜索来找到相关记录的内部 ID。问题:N/search 模块在我当前正在编码的工作流操作脚本中不可用。
为了使问题更具体,我的用户提取了一个总帐帐户记录 ('account'),他们打算将其删除。我有一个 NS 捆绑包,可以作为第三方软件的集成器。 NS 捆绑包具有一个值转换 table,可将 NS 帐户代码映射到第 3 方软件代码。每个值转换都存在于捆绑包创建的自定义记录 ('icvt') 中,我需要删除值转换记录。我希望使用 N/search 来查找 icvt 记录,但我无法在工作流操作脚本中使用搜索。
求助。
编辑:刚刚意识到我想我误解了文档,并且 N/search 是 可用的,所以我的错误一定是在其他地方。
编辑以添加代码。这是我在意识到模块对我不可用之前使用的搜索代码:
/**
*@NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
// Deletes Value Transform related to account deleted.
define(['N/record', 'N/search', 'N/log'], function (record, search, log) {
function wfDeleteICVT(scriptContext) {
var deleted_account = scriptContext.newRecord;
var da_internalID = deleted_account.getValue("id");
var v_da_internalID = da_internalID.toString();
var mySearch = search.create({
type: 'icvt',
filters: [
search.createFilter({
name: 'sourcevalue',
operator: search.Operator.IS,
values: v_da_internalID
})
]
});
//log.debug(v_da_internalID)
var myResultSet = mySearch.run();
var myResultRange = myResultSet.getRange(0,1);
log.debug({title: myResultRange.length, details: myResultSet})
var deleted_icvt = mySearch[0];
var di_icvt = deleted_icvt.id;
deleted_icvt.delete({
type: 'icvt',
id: di_internalID
});
}
return {
onAction : wfDeleteICVT
}
});
如果您能够获取需要删除的记录的 ID,则可以使用 N/record
模块和 record.delete(options)
来删除所需的记录。
// Delete a sales order.
var salesOrderRecord = record.delete({
type: record.Type.SALES_ORDER,
id: 88,
});
// Delete an instance of a custom record type with the ID customrecord_feature.
var featureRecord = record.delete({
type: 'customrecord_feature',
id: 3,
});
编辑-
N/search
模块 works 在工作流动作脚本上。我自己用过很多次。为什么不在 Netsuite 的 UI 中创建保存的搜索,然后将其导出为脚本并在脚本中使用它?
要导出 - 您可以使用下面的 Chrome 扩展程序。
此外,我可以看到您在 search.create
方法中创建了过滤器,但没有添加任何列。这可能是问题所在。
告诉我。
这是有效的最终解决方案。我最初的假设是完全错误的,我不能使用搜索,所以这是最终的解决方案,尽管我确实接受了@sayeesh 的建议并使用了通过 UI:
创建的搜索
/**
*@NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
// Deletes Value Transform related to account deleted.
define(['N/record', 'N/search', 'N/log'], function (record, search, log) {
function icvtDelete(scriptContext) {
var deleted_account = scriptContext.newRecord; //gets the account record of the current account
var da_internalID = deleted_account.getValue("id"); //gets the internal id of the current account
var v_da_internalID = da_internalID.toString(); //converts the internal id to a string for comparison later
var mySearch = search.load({
id: "customsearch_icvt_search"}); //loads a saved search
var mySearchResult = mySearch.run(); //runs the saved search
var myResults = mySearchResult.getRange(0,1000); //gets the range of results
for(var i in myResults){ //iterates through the results
var result = myResults[i]; //load a result
if(result.getValue('custrecordictransformationvalue') == v_da_internalID) //if the result is the one we're looking for
{
var icvt_to_delete = record.load({
type: 'mycustomrecord',
id: result.getValue('id')
});
log.debug(v_da_internalID, result.getValue('id'));
icvt_to_delete.setValue({fieldId: 'deletionreason', value: 1});
icvt_to_delete.setValue({fieldId: 'deletionreasonmemo', value: 'SS2.0 Delete reason saved using Load/Save'});
icvt_to_delete.save();
record.delete({
type: 'mycustomrecord',
id: result.getValue('id')
});
}
}
}
return {
onAction : icvtDelete
}
});
我正在尝试删除与使用工作流操作脚本加载的当前记录相关的记录。我看过类似问题的其他答案,说我可以通过使用关键字段中的值作为搜索参数进行搜索来找到相关记录的内部 ID。问题:N/search 模块在我当前正在编码的工作流操作脚本中不可用。
为了使问题更具体,我的用户提取了一个总帐帐户记录 ('account'),他们打算将其删除。我有一个 NS 捆绑包,可以作为第三方软件的集成器。 NS 捆绑包具有一个值转换 table,可将 NS 帐户代码映射到第 3 方软件代码。每个值转换都存在于捆绑包创建的自定义记录 ('icvt') 中,我需要删除值转换记录。我希望使用 N/search 来查找 icvt 记录,但我无法在工作流操作脚本中使用搜索。
求助。
编辑:刚刚意识到我想我误解了文档,并且 N/search 是 可用的,所以我的错误一定是在其他地方。
编辑以添加代码。这是我在意识到模块对我不可用之前使用的搜索代码:
/**
*@NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
// Deletes Value Transform related to account deleted.
define(['N/record', 'N/search', 'N/log'], function (record, search, log) {
function wfDeleteICVT(scriptContext) {
var deleted_account = scriptContext.newRecord;
var da_internalID = deleted_account.getValue("id");
var v_da_internalID = da_internalID.toString();
var mySearch = search.create({
type: 'icvt',
filters: [
search.createFilter({
name: 'sourcevalue',
operator: search.Operator.IS,
values: v_da_internalID
})
]
});
//log.debug(v_da_internalID)
var myResultSet = mySearch.run();
var myResultRange = myResultSet.getRange(0,1);
log.debug({title: myResultRange.length, details: myResultSet})
var deleted_icvt = mySearch[0];
var di_icvt = deleted_icvt.id;
deleted_icvt.delete({
type: 'icvt',
id: di_internalID
});
}
return {
onAction : wfDeleteICVT
}
});
如果您能够获取需要删除的记录的 ID,则可以使用 N/record
模块和 record.delete(options)
来删除所需的记录。
// Delete a sales order.
var salesOrderRecord = record.delete({
type: record.Type.SALES_ORDER,
id: 88,
});
// Delete an instance of a custom record type with the ID customrecord_feature.
var featureRecord = record.delete({
type: 'customrecord_feature',
id: 3,
});
编辑-
N/search
模块 works 在工作流动作脚本上。我自己用过很多次。为什么不在 Netsuite 的 UI 中创建保存的搜索,然后将其导出为脚本并在脚本中使用它?
要导出 - 您可以使用下面的 Chrome 扩展程序。
此外,我可以看到您在 search.create
方法中创建了过滤器,但没有添加任何列。这可能是问题所在。
告诉我。
这是有效的最终解决方案。我最初的假设是完全错误的,我不能使用搜索,所以这是最终的解决方案,尽管我确实接受了@sayeesh 的建议并使用了通过 UI:
创建的搜索/**
*@NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
// Deletes Value Transform related to account deleted.
define(['N/record', 'N/search', 'N/log'], function (record, search, log) {
function icvtDelete(scriptContext) {
var deleted_account = scriptContext.newRecord; //gets the account record of the current account
var da_internalID = deleted_account.getValue("id"); //gets the internal id of the current account
var v_da_internalID = da_internalID.toString(); //converts the internal id to a string for comparison later
var mySearch = search.load({
id: "customsearch_icvt_search"}); //loads a saved search
var mySearchResult = mySearch.run(); //runs the saved search
var myResults = mySearchResult.getRange(0,1000); //gets the range of results
for(var i in myResults){ //iterates through the results
var result = myResults[i]; //load a result
if(result.getValue('custrecordictransformationvalue') == v_da_internalID) //if the result is the one we're looking for
{
var icvt_to_delete = record.load({
type: 'mycustomrecord',
id: result.getValue('id')
});
log.debug(v_da_internalID, result.getValue('id'));
icvt_to_delete.setValue({fieldId: 'deletionreason', value: 1});
icvt_to_delete.setValue({fieldId: 'deletionreasonmemo', value: 'SS2.0 Delete reason saved using Load/Save'});
icvt_to_delete.save();
record.delete({
type: 'mycustomrecord',
id: result.getValue('id')
});
}
}
}
return {
onAction : icvtDelete
}
});