Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetSuite custom record search through suiteTalk using C#

Tags:

c#

netsuite

We are having an issue with searching a custom record through 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. 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. When we made the record we assigned its “scriptId’ to be 'customrecord_myCustomRecord' but through suitetalk we do not have a “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. We are using the 2013.2 endpoints at this time.

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

        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;
    }
like image 657
cepatt Avatar asked Feb 18 '14 16:02

cepatt


1 Answers

I searched all over for a solution to avoid hardcoding internalId's. Even NetSuite support failed to give me a solution. Finally I stumbled upon a solution in NetSuite's knowledgebase, 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.)

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;
}
like image 126
Matt Avatar answered Oct 21 '22 07:10

Matt