systems | willwatkinson

Getting Netsuite field types from the WSDL in Python

Written by Will Watkinson | Nov 19, 2018 2:38:15 PM

In Netsuite different field types can require a different XML structure to be input as the value of the field. Most notably this applies to Netsuite Record Reference fields, RecordRef in the WSDL You can know what all the RecordRef fields on all the objects are, or at least the ones you want to interact with, and just hard code them, but it can be nice to be able to dynamically retrieve them on any object.

Using the netsuite library for python you can get all of the object element details using the following code:

client = NetSuite(**creds, sandbox=False, version = '2017.2.0')

info = client...elements

This will return an ordered dictionary of all the fields and their details. To generate a list of all the RecordRef fields simply loop through the field info and add the field name to the list if it is a RecordRef field:

record_ref_fields = []

for element in info:

#the type information is located within the second ordered dictionary entry of each element

if str(element[1].type).find('RecordRef') > -1:

record_ref_fields.append(element[0])

When you are populated the zeep object to make a request to Netsuite you can use this list to decide whether you need to use the RecordRef structure as the value for that Netsuite field.

A few notes: the WSDL does not contain your Netsuite org’s custom fields, so this will not get the types of your custom fields; the type information contains the namespace and all information necessary for navigating the WSDL to the WSDL structure, so you could make this more dynamic for more field types if you wanted.