'How to search for all records of of type CustomRecordType in Netsuite?

I am trying to get all the records related to a custom record type. How to do it in Netsuite SOAP? Also is there a way to search records of that custom record type by it's recordname?

Something like this returns only the first record:

CustomRecordRef customRec = new CustomRecordRef();
customRec.setInternalId("XXX");
customRec.setScriptId("customrecord_lc_mapping");
netsuiteSoapClient.getPort(true).get(customRec);


Solution 1:[1]

Here is an example code on how to query all the values of a custom record type using Java SOAP:

/**
 * String search Cost Template Values
 * 
 * @return internal ID
 * @throws Any Exception
 */
private Map<String, String> searchCostTemplateValues() throws Exception {
    CustomRecordSearchBasic customRecordSearch = new CustomRecordSearchBasic();
    RecordRef recordRef = new RecordRef();
    
    if(environment.toLowerCase().equals("test") || environment.equals("default")) {
        recordRef.setInternalId("426");
    }
    else {
        recordRef.setInternalId("426");
    }
    customRecordSearch.setRecType(recordRef);
    SearchResult response = netsuiteSoapClient
            .getPort(true)
            .search(customRecordSearch);
    LOGGER.info("Search Result: " + new ObjectMapper()
            .writerWithDefaultPrettyPrinter().writeValueAsString(response));
    RecordList costTemplateRecordList = response.getRecordList();
    Record[] customRecordArray = costTemplateRecordList.getRecord();
    Map<String, String> costTemplateMap = new HashMap<>();
    for(Record r : customRecordArray) {
        CustomRecord cr = (CustomRecord) r;
        String name = cr.getName();
        String internalId = cr.getInternalId();
        costTemplateMap.put(name, internalId);
    }
    return costTemplateMap;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pritam Banerjee