This codesnippet shows how to retrieve the value of a specific custom field specified in the search column afterperforming an Advanced Search in Web Services. This sample demonstrates anAdvanced Customer Search with one search criterion (customer's Internal ID) andone search column (string custom field).
Sample codesnippet in C#:
// Instantiate a search object for customers.
CustomerSearchAdvanced custSearchAdv = new CustomerSearchAdvanced();
CustomerSearch custSearch = new CustomerSearch();
CustomerSearchBasic custSearchBasic = new CustomerSearchBasic();
// Instantiate search return column objects for customers.
setSearchPreferences(false, true);
CustomerSearchRow custSearchRow = new CustomerSearchRow();
CustomerSearchRowBasic custSearchRowBasic = new CustomerSearchRowBasic();
// Define the criteria using the customer's Internal ID
RecordRef[] recRef = new RecordRef[1];
RecordRef entityRef = new RecordRef();
entityRef.internalId = "314"; // customer's Internal ID
recRef[0] = entityRef;
SearchMultiSelectField IntID = new SearchMultiSelectField();
IntID.@operator = SearchMultiSelectFieldOperator.anyOf;
IntID.operatorSpecified = true;
IntID.searchValue = recRef;
custSearchBasic.internalId = IntID;
// Define return columns
// SearchColumnStringCustomField is used since the custom field type = free-form text
SearchColumnStringCustomField stringcols = new SearchColumnStringCustomField();
stringcols.internalId = "custentity9"; //the custom field's Internal ID
// From SuiteTalk version 2013.2
// stringcols.scriptId= "custentity9";
SearchColumnCustomField[] customField = new SearchColumnCustomField[1];
customField[0] = stringcols;
// Set return columns
custSearchRowBasic.customFieldList = customField;
// Apply search criteria
custSearch.basic = custSearchBasic;
custSearchAdv.criteria = custSearch;
// Apply search return columns
custSearchRow.basic = custSearchRowBasic;
custSearchAdv.columns = custSearchRow;
SearchResult response = _service.search(custSearchAdv);
if (response.status.isSuccess)
{
SearchRow[] records = response.searchRowList;
CustomerSearchRow customerRow = (CustomerSearchRow)records[0];
CustomerSearchRowBasic customerRowBasic = customerRow.basic;
//Assign the customFieldList value to a SearchColumnCustomField array
SearchColumnCustomField[] customField = customerRow.basic.customFieldList;
for (int k = 0; k < customField.Length; k++)
{
//Cast customField to its data type and retrieve the custom field's value
SearchColumnStringCustomField custField = (SearchColumnStringCustomField)customField[k];
_out.info("\n Custom Field Internal ID is " + custField.internalId +
"\n Custom Field Value is " + custField.searchValue);
}
}
Note: Code replicates saved search definition and behavior.
No comments:
Post a Comment