-->

NetSuite SuiteTalk - Retrieve Value String From “S

2020-03-07 08:46发布

问题:

I have a small application that iterates over the results of a "Saved Search" retrieving the values from several Custom Columns(simplified example):

var results = searchResults.Select(a => new
{
    X = ((SearchColumnBooleanCustomField)a.basic.customFieldList
        .First(b => b.scriptId == "custentityX")).searchValue
    Y = ((SearchColumnDateCustomField)a.basic.customFieldList
        .First(b => b.scriptId == "custentityY")).searchValue
    Z = ((SearchColumnSelectCustomField)a.basic.customFieldList
        .First(b => b.scriptId == "custentityZ")).searchValue.name
}

For most returned column types I get a value consistent with the type(bool/date/etc...) but with the "SearchColumnSelectCustomField" I don't get any value in the returned "searchValue.name", it's always null, however the "searchValue.internalID" column is always populated. So for some reason its getting the selection but not returning the value from that selection.

How do I access the text value that I can see from the NetSuite interface from SuiteTalk("searchValue.name")? Do I have to execute another query to retrieve all value key pairs related to that internalID? For every custom field? And if so then what is the purpose of the name field in the first place?

I've tried searching around for this, but there's not really allot of documentation on the subject(or on SuiteTalk in general), in other languages(PHP/Java) people mention "getSelectValue"(here, and briefly here), I could try this in C#, but I'm not sure if these apply or if that can be done for custom value selections. Then there's some references for determining the values BEFORE the search, this seems like overkill to me, is it really that hard? I have dozens of CustomFields I would like to access in my final application. Seems like there should be an easier way...

回答1:

As far as I know, the web service response will only contain the internalId and typeId for a SearchColumnSelectCustomField. In order to get the name, you'll have to first query NetSuite to find all custom lists and their values.

You can do this using a CustomListSearch and set the bodyFieldsOnly search preference to false. Pass in no criteria to the CustomListSearch and you'll be returned every custom list and their values. Just store there results in memory and reference it when reading the column values from your saved search.



回答2:

I tried the answer posted by @Adud123 and it works great, Here's what the code looks like:

public Dictionary<string, Dictionary<long, string>> getCustomFieldLists()
{
    return
        nsService.search(new CustomListSearch())
            .recordList.Select(a => (CustomList) a)
            .ToDictionary(a => a.internalId,
                a => a.customValueList.customValue
                     .ToDictionary(b => b.valueId, c => c.value));
}

var valueLookup = getCustomFieldLists();

var results = searchResults.Select(a => new
{
    Z = (a.basic.customFieldList.Where(b => b.scriptId == "custentityZ")
        .Select(a => (SearchColumnSelectCustomField)a)
        .Select(a => valueLookup[a.searchValue.typeId][a.searchValue.internalId])
        .First()
}