Skip to main content
 首页 » 编程设计

Python之如何使用 NetSuite web 服务设置自定义字段

2024年09月07日42zhwl

我正在尝试使用网络服务在 NetSuite 中设置自定义字段。 我使用的 WSDL 是:https://webservices.netsuite.com/wsdl/v2017_2_0/netsuite.wsdl

目前我正在测试创建客户。这是我到目前为止所拥有的:

def add_customer(): 
  client = login_client() 
  RecordRef = client.get_type('ns0:RecordRef') 
  Customer = client.get_type('ns13:Customer') 
  customer = Customer( 
    companyName='TEST', 
    subsidiary = RecordRef(internalId='5', type='subsidiary') 
  ) 
  response = client.service.add(customer) 
  print(response)  
 
add_customer() 

这非常有效,但现在我正在尝试设置一个 ID 为 custfield1 的自定义字段 经过一番搜索,我发现:

http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/schema/other/customfieldlist.html?mode=package

从这个链接我知道我将需要使用 CustomFieldRef,我只是不确定它是如何实现的。

请您参考如下方法:

我找到了一种方法:

def add_customer(): 
   client = login_client() 
   RecordRef = client.get_type('ns0:RecordRef') 
   StringCustomFieldRef = client.get_type('ns0:StringCustomFieldRef') #StringCustomFieldRef 
   CustomFieldList = client.get_type('ns0:CustomFieldList') #To go from object to list 
 
   #Cust field 1 
   acctName = StringCustomFieldRef() 
   acctName.internalID = '1569' 
   acctName.scriptId = 'custentity_account_name' 
   acctName.value = 'testData' 
 
   #custField2 
   acctID= StringCustomFieldRef() 
   acctID.internalId= '1596' 
   acctID.scriptId= 'custentity_sf_account_id' 
   acctID.value = 'FIELD DATA' 
 
   Customer = client.get_type('ns13:Customer') 
   customer = Customer( 
      companyName='TEST', 
      entityId='TEST ID', 
      subsidiary = RecordRef(internalId='5', type='subsidiary'), 
      customFieldList = CustomFieldList([acctID,acctName]) #List of cust objects 
   ) 
   response = client.service.add(customer) 
   print(response) 
 
add_customer() 

您必须为正在使用的字段使用 Ref 类型:https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_n3458179.html