Reputation: 165
I have created a new custom record called "XYZ" and i created all the fields into it. Now i can add new entry on that Custom record using GUI but how do i do similar action using webservices.
What methods needs to be summoned to add new item in custom record type and how do we do it. Any help would be greatly appreciated.
Thank You
Upvotes: 4
Views: 3674
Reputation: 187
Below is the sample C# code to add custom record using SuiteTalk (webservices) -
CustomRecord customRecord = new CustomRecord();
RecordRef recordType = new RecordRef();
recordType.internalId = "14"; // // Record Type's internal ID (Setup > Customization > Record Types > Basic Record Type (Internal ID=14)
recordType.type = RecordType.customRecord;
recordType.typeSpecified = true;
customRecord.recType = recordType;
customRecord.internalId = "7"; // internal id of the custom record you want to update
StringCustomFieldRef stringCustomFieldRef = new StringCustomFieldRef();
stringCustomFieldRef.scriptId = "custrecord_pe_pbmastertrackno";
stringCustomFieldRef.value = txtMasterTrackno.Text.Trim();
CustomFieldRef[] customFieldRef = new CustomFieldRef[1];
customFieldRef[0] = stringCustomFieldRef;
customRecord.customFieldList = customFieldRef;
_service = new NetSuiteService();
setPassport(); // Set the Passport information for authentication
WriteResponse writeResponse = _service.add(customRecord);
Hope this will help you.
Thanks.
Upvotes: 3
Reputation: 129
You can create new restlet with following code and call restlet using post method with recordtype and field values
function createNewRecord(datain){
var recType = datain.recordtype;
var field1 = datain.field1;
var field2 = datain.field2;
var field3 = datain.field3;
var record = nlapiCreateRecord(recType);
record.setFieldValue('custrecord_field1', field1);
record.setFieldValue('custrecord_field2', field2);
record.setFieldValue('custrecord_field3', field3);
var id = nlapiSubmitRecord(record, true);
var dd = JSON.stringify(id);
return dd;
}
Restlet Call
var account = 'XXXXXXX';
var email = '[email protected]';
var signature = 'XXXXXXXX';
var role = '3';
var recordtype = 'XYZ';
var custrecord_field1 = 'value1';
var custrecord_field2 = 'value2';
var custrecord_field3 = 'value3';
var newRec = {"recordtype": recordtype, "field1":custrecord_field1, "field2":custrecord_field2, "field3":custrecord_field3}
var url = 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=231&deploy=1';
var params = {
contentType: 'application/json',
headers:{Authorization: 'NLAuth nlauth_account='+account+', nlauth_email='+email+', nlauth_signature='+signature+', nlauth_role='+role},
method: 'POST',
muteHttpExceptions: true,
payload: JSON.stringify(newRec)
};
var response = UrlFetchApp.fetch(url, params);
var resdata = JSON.parse(response.getContentText());
Logger.log(resdata);
Upvotes: 0