In order to create or update a custom record through SuiteTalk, we need to first create an object of the ‘CustomRecord’ class and assign the internal id of the record type, we are going to work on, to it.
CustomRecord customRecord = new CustomRecord();
Now we assign the internal id of the custom record to this ‘customRecord’ object
RecordRef recRef = new RecordRef();
recRef.internalId =”298″;//setting the internal id of the netsuite custom record
customRecord.recType = recRef;
In order to set the values of the record fields , we need to create an object of StringCustomFieldRef,BooleanCustomFieldRef,DateCustomFieldRef,etc. as per our requirement and field type.
//setting the value of the string field StringCustomFieldRef customField1 = new StringCustomFieldRef(); customField.value = "[email protected]";//value to be assigned customField.internalId = "custrecord1";//internal id of the field //setting the value of the checkbox field BooleanCustomFieldRef customField2 = new BooleanCustomFieldRef(); customField.value = true;//value to be assigned customField.internalId = "custrecord2";//internal id of the field
In order to attach these values to the customRecord object, we use a CustomFieldRef array and pass the objects of the custom fields in it. customRecord.customFieldList = new CustomFieldRef[] { customField1,customField2 }; If we want to create a new custom record, then we use the add method of the NetsuiteService class like, var response=_netsuiteService.add(customRecord); In a similar way, we can update a custom record also. |
Searching a custom record: In order to implement a search on a custom record through suitetalk , we need to work with CustomRecordSearch and CustomRecordSearchBasic classes. CustomRecordSearch custRecSearch = new CustomRecordSearch(); CustomRecordSearchBasic custRecSearchBasic = new CustomRecordSearchBasic(); Then we specify the internal id of the custom record on which this search has to be applied RecordRef recRef = new RecordRef(); recRef.internalId = “49”;//setting the internal id of the custom record type custRecSearchBasic.recType = recRef; For adding search filter , we can choose among SearchStringCustomField ,SearchDateCustomField ,SearchDoubleCustomField ,etc. as per our requirements. |
//adding a search filter on a String Custom Field SearchStringCustomField searchFilter1 = new SearchStringCustomField(); searchFilter1.internalId = "custrecord_customer_custom_form";//internal id of the custom field you are going to apply filter on searchFilter1.@operator = SearchStringFieldOperator.contains;//search operator searchFilter1.operatorSpecified = true; searchFilter1.searchValue = "a";//search filter value In order to add the search filters to the search, we use SearchCustomField custRecSearchBasic.customFieldList = new SearchCustomField[] { searchFilter1 };
In order to execute the search ,we simple use the search method of the NetsuiteService class
custRecSearch.basic = custRecSearchBasic;
SearchResult result = _NetsuiteService.search(custRecSearch);//executing search
Now we can use this result and obtain the search values from it.