如何使用webservices在netsuite中添加新的自定义记录项?

时间:2016-08-02 21:53:10

标签: netsuite suitescript k2 suitetalk

我创建了一个名为“XYZ”的新自定义记录,并在其中创建了所有字段。 现在我可以使用GUI在该自定义记录上添加新条目,但如何使用webservices执行类似操作。

需要召唤哪些方法在自定义记录类型中添加新项目以及我们如何执行此操作。 任何帮助将不胜感激。

谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用以下代码创建新的restlet,并使用带有记录类型和字段值的post方法调用restlet

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 = 'XXXX@domain.com';
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);

答案 1 :(得分:0)

以下是使用SuiteTalk(webservices)添加自定义记录的示例C#代码 -

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);

希望这会对你有所帮助。

感谢。