问题
Say you are trying to access a value from SuiteTalk that is returned as type "SearchColumnSelectField":
((TransactionSearchRow)row).basic.postingPeriod?[0].searchValue.name
Note: I use postingPeriod as example, but there are many other records that return a "searchValue" of type "RecordRef" that have the same issue.
This("searchValue.name") will be null, similar to the issue detailed here, but unlike with CustomFields I don't see any documented way of retrieving the lookup values based on the "internalId" of the returned "searchValue"(typically populated). To further complicate things, the returned object does not appear to have a "typeId" specified. It looks something like this:
So again I wonder, How do I access the text value that I can see from the NetSuite interface from SuiteTalk("searchValue.name")? NetSuite documentation is lacking, clearly in this case it's of type "period", but how does one enumerate that? Or in this case maybe there is a different way to go about retrieving the value?
I've been looking around, but there's not a whole lot written about this. I think this issue is mentioned in this post. Other than that I really can't find anything. I've already checked the API documentation, here and here, it's not much help, I wonder if there is some sort of internal documentation on the subject that I'm not seeing, but from what I've read there's really, not much.
回答1:
I have found what appears to be the answer by trying all the get and search methods in SuiteTalk tell I found one that was capable of returning the correct type of results:
NetSuiteService nsService = ... //Your NetSuiteService
IEnumerable<TransactionSearchRow> rows = ... //The results of your query
var lookup = nsService.getList(rows.
Where(a => a.basic.postingPeriod.Any())
.Select(a =>
{
var value = a.basic.postingPeriod[0].searchValue;
value.type = RecordType.accountingPeriod;
value.typeSpecified = true;
return value;
})
.GroupBy(a => a.internalId)
.Select(a => a.First())
.ToArray()).readResponse
.ToDictionary(a => ((AccountingPeriod)a.record).internalId,
a => ((AccountingPeriod)a.record).periodName);
var allPeriods = rows
.Select(a => a.basic.postingPeriod.Any() ?
lookup[a.basic.postingPeriod[0].searchValue.internalId] : "")
.ToArray();
This method is listed here, but it doesn't really provided sufficient detail. Also, I'm not sure why:
Period(Column) = a.basic.postingPeriod(Property) = RecordType.accountingPeriod(Property) = AccountingPeriod(Type)
I guess one sort of has to guess what each type corresponds too. For period its not too bad, but for some of the other ones it can be a little confusing.
I hope this helps someone else out, for me its been a difficult process. If anyone else has any other solutions I'm still open to suggestions. I'm still not sure this is the most efficient method of data retrieval.
来源:https://stackoverflow.com/questions/40517053/netsuite-suitetalk-retrieve-value-string-from-searchcolumnselectfield