Wednesday, 3 January 2018

Retrieving customer part numbers from NetSuite

I couldn't find any documentation on retrieving customer part numbers from NetSuite and it took an age to find what I needed.  Here's the end code for cribbing - needs tidying up but you can extract what you need to do in SuiteTalk from it:

// Find the customization id for customrecord_scm_customerpartnumber here
public String getCustomizationId(String scriptId) throws Exception
{
    CustomizationType ct = new CustomizationType();

    ct.setGetCustomizationType(GetCustomizationType.CUSTOM_RECORD_TYPE);

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

    for (CustomizationRef customizationRef : getCustIdResult.getCustomizationRefList().getCustomizationRef())
    {
        if (customizationRef.getScriptId().equals(scriptId)) return customizationRef.getInternalId();
    }

    return null;
}

....

// Configure search objectsCustomRecordSearch customerPartNumberRecordSearch = new CustomRecordSearch();
SearchCustomFieldList searchCustomFieldList = new SearchCustomFieldList();
CustomRecordSearchBasic customerPartNumberRecordSearchBasic = new CustomRecordSearchBasic();
customerPartNumberRecordSearchBasic.setCustomFieldList(searchCustomFieldList);
customerPartNumberRecordSearch.setBasic(customerPartNumberRecordSearchBasic);


// Filter by the customer part number record typecustomerPartNumberRecordSearchBasic.setRecType(new RecordRef());
customerPartNumberRecordSearchBasic.getRecType().setInternalId(*ID of customization*); // This is the internal id of the custom record type
// Filter by the customer idSearchMultiSelectCustomField customerFilter = new SearchMultiSelectCustomField();
customerFilter.setScriptId("custrecord_scm_cpn_customer");
customerFilter.setOperator(SearchMultiSelectFieldOperator.ANY_OF);
ListOrRecordRef customerRecordRef = new ListOrRecordRef();
customerRecordRef.setInternalId(customerId);
customerFilter.getSearchValue().add(customerRecordRef);
searchCustomFieldList.getCustomField().add(customerFilter);

// Filter by the inventory item idSearchMultiSelectCustomField itemFilter = new SearchMultiSelectCustomField();
itemFilter.setScriptId("custrecord_scm_cpn_item");
itemFilter.setOperator(SearchMultiSelectFieldOperator.ANY_OF);
ListOrRecordRef itemRecordRef = new ListOrRecordRef();
itemRecordRef.setInternalId(itemNumer);
itemFilter.getSearchValue().add(itemRecordRef);
searchCustomFieldList.getCustomField().add(itemFilter);
customerPartNumberRecordSearchBasic.setCustomFieldList(searchCustomFieldList);

// Search for the customer entitySearchResult partNumbersSearchResult = port.search(customerPartNumberRecordSearch);


return ((CustomRecord)partNumbersSearchResult.getRecordList().getRecord().get(0)).getName();

No comments:

Post a Comment