简体   繁体   English

使用C#通过suiteTalk进行NetSuite自定义记录搜索

[英]NetSuite custom record search through suiteTalk using C#

We are having an issue with searching a custom record through SuiteTalk. 我们在通过SuiteTalk搜索自定义记录时遇到问题。 Below is a sample of what we are calling. 以下是我们呼吁的样本。 The issue we are having is in trying to set up the search using the internalId of the record. 我们遇到的问题是尝试使用记录的internalId设置搜索。 The issue here lies in in our initial development account the internal id of this custom record is 482 but when we deployed it through the our bundle the record was assigned with the internal Id of 314. It would stand to reason that this internal id is not static in a site per site install so we wondered what property to set up to reference the custom record. 这里的问题在于我们的初始开发帐户中这个自定义记录的内部id是482但是当我们通过我们的bundle部署它时,记录被分配了内部Id为314.这可能是因为这个内部id不是每个站点安装一个站点中的静态,所以我们想知道要设置什么属性来引用自定义记录。 When we made the record we assigned its “scriptId' to be 'customrecord_myCustomRecord' but through suitetalk we do not have a “scriptId”. 当我们创建记录时,我们将其“scriptId”指定为'customrecord_myCustomRecord'但是通过suitetalk我们没有“scriptId”。 What is the best way for us to allow for this code to work in all environments and not a specific one? 我们允许此代码在所有环境中工作而不是特定环境的最佳方式是什么? And if so, could you give an example of how it might be used. 如果是这样,你能举例说明它是如何使用的。

Code (C#) that we are attempting to make the call from. 我们试图从中调用的代码(C#)。 We are using the 2013.2 endpoints at this time. 我们目前正在使用2013.2端点。

private SearchResult NetSuite_getPackageContentsCustomRecord(string sParentRef) { List PackageSearchResults = new List(); private SearchResult NetSuite_getPackageContentsCustomRecord(string sParentRef){List PackageSearchResults = new List();

    CustomRecord custRec = new CustomRecord();

    CustomRecordSearch customRecordSearch = new CustomRecordSearch();

    SearchMultiSelectCustomField searchFilter1 = new SearchMultiSelectCustomField();
    searchFilter1.internalId = "customrecord_myCustomRecord_sublist";
    searchFilter1.@operator = SearchMultiSelectFieldOperator.anyOf;
    searchFilter1.operatorSpecified = true;
    ListOrRecordRef lRecordRef = new ListOrRecordRef();
    lRecordRef.internalId = sParentRef;
    searchFilter1.searchValue = new ListOrRecordRef[] { lRecordRef };

    CustomRecordSearchBasic customRecordBasic = new CustomRecordSearchBasic();
    customRecordBasic.recType = new RecordRef();
    customRecordBasic.recType.internalId = "314";  // "482";  //THIS LINE IS GIVING US THE TROUBLE
    //customRecordBasic.recType.name = "customrecord_myCustomRecord";
    customRecordBasic.customFieldList = new SearchCustomField[] { searchFilter1 };

    customRecordSearch.basic = customRecordBasic;

    // Search for the customer entity
    SearchResult results = _service.search(customRecordSearch);

    return results;
}

I searched all over for a solution to avoid hardcoding internalId's. 我搜遍了一个解决方案,以避免硬编码internalId。 Even NetSuite support failed to give me a solution. 甚至NetSuite支持都没能给我一个解决方案。 Finally I stumbled upon a solution in NetSuite's knowledgebase, getCustomizationId . 最后,我在NetSuite的知识库getCustomizationId中偶然发现了一个解决方案。

This returns the internalId, scriptId and name for all customRecord's (or customRecordType's in NetSuite terms! Which is what made it hard to find.) 这将返回所有customRecord的internalId,scriptId和name(或NetSuite条款中的customRecordType!这是很难找到的。)

public string GetCustomizationId(string scriptId)
{
    // Perform getCustomizationId on custom record type
    CustomizationType ct = new CustomizationType();
    ct.getCustomizationTypeSpecified = true;
    ct.getCustomizationType = GetCustomizationType.customRecordType;

    // Retrieve active custom record type IDs. The includeInactives param is set to false.
    GetCustomizationIdResult getCustIdResult = _service.getCustomizationId(ct, false);

    foreach (var customizationRef in getCustIdResult.customizationRefList)
    {
        if (customizationRef.scriptId == scriptId) return customizationRef.internalId;
    }

    return null;
}

you can make the internalid as an external property so that you can change it according to environment. 您可以将internalid作为外部属性,以便您可以根据环境进行更改。 The internalId will be changed only when you install first time into an environment. 只有在第一次安装到环境中时,才会更改internalId。 when you deploy it into that environment, the internalid will not change with the future deployments unless you choose Add/Rename option during deployment. 将它部署到该环境时,除非在部署期间选择“添加/重命名”选项,否则internalid将不会随将来的部署而更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM