Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

JSON examples for subrecords, sublists, etc. #14

Open
mperham opened this issue May 28, 2013 · 11 comments
Open

JSON examples for subrecords, sublists, etc. #14

mperham opened this issue May 28, 2013 · 11 comments

Comments

@mperham
Copy link
Contributor

mperham commented May 28, 2013

I'm just starting to learn the complexity of NetSuite's domain model. We're struggling to upsert a complex object (in our case, a PurchaseOrder) and could use some real examples of inserting a complex object including sublists with subrecords.

You do have some abstract documentation on the request structure but it's difficult for us to map that onto a real world example.

@cmhobbs
Copy link
Contributor

cmhobbs commented May 29, 2013

@JamesChristie care to chime in?

I believe Netsuite interaction is complex in any instance, so it's hard to provide a generic data structure format without exposing some of our custom setup.

@JamesChristie
Copy link
Contributor

I'll update the README with example structure of request formatted as valid JSON as opposed to the tree structure we're using at the moment.

@apbit
Copy link

apbit commented Jun 26, 2013

I'm faily new with Netsuite and their SuiteScript API and I want to change our current soap web services into restlets calls. I really like this project but since I'm not familiar with it, I would love some guidance. I got the initialize and load to work. By the way, Initialize doesn't work on NetSuite for me. I had to switch it to nlapiCreateRecord. My problem right now is with the sales order upsert. Take for example the following request body:

[{
"record_data":
{
"internalid":1234567,
"record_type":"salesorder",
"literal_fields":[{"memo":"rest test"}]
}
}]

And I can't get it to work. I'm assume it's something wrong with my body. The closest error to get it to work is an error: "TypeError: Cannot call method "setFieldValue" of undefined (netsuite_toolkit.js#90)", and actually with this body, just like it is, I do get a "success:true", but no changes to the data.

Thank you!

@apbit
Copy link

apbit commented Jun 27, 2013

I finally was able to get the debugging working. Through that I was able to get my body:
{
"record_data":
[{
"internalid":1234567,
"record_type":"salesorder",
"literal_fields":{"memo":"rest rest"}
}]
}

And... found a bug on Upsert.js. In UpsertRequest.prototype.loadOrInitializeRecord(), the record object is assigned to either the results of loadRecord or initializeRecord, and nothing is returned... however, in UpsertRequest.prototype.execute(), the record object is assigned to whatever the loadOrInitializeRecord returns, which is null. I apolize if I should've created another issue for this. I don't have the dev branch setup yet so I can't make code changes, but I just wanted to point it to you guys.

Thank you for this awesome project!

@apbit
Copy link

apbit commented Jun 27, 2013

I have a real world example, I needed to update the quantity of an item of a sales order. Here's the body I came with:
{
"record_data":
[{
"internalid": 1234567,
"record_type": "salesorder",
"sublists":
[ {
"name": "item",
"update":
[ {
"index": 1,
"data":
{
"amount":10,
"quantity":2
}
}]
}]
}]

The important thing for me was to look for the elements expected in sublists.... it needs the name (item, salesteam, etc), the action to do with the item: "create, update" and the way you find the item that needs to be updated, either by index (starting with 1, row-based) or by match.

@ephemer
Copy link

ephemer commented Mar 20, 2014

@apbit what did you do about the bug you found in Upsert.js?
I'm trying to update customer records, which I gather are just literals but I'm getting the same error you were: "TypeError: Cannot call method "setFieldValue" of undefined (netsuite_toolkit.js#90)"

Here's my body. I'm assuming I don't need the empty sublists object, but just put it there to make sure.. I can't seem to get my scripts showing up in the Netsuite Debugger so this is a slow and frustrating process.

{
  "record_data":
  [{
    "internalid":"142147",
    "record_type":"customer",
    "literal_fields": {
      "phone": "987654321"
    },
    "sublists": {}
  }]
}

@ephemer
Copy link

ephemer commented Mar 21, 2014

I got the debugger working and found the code in upstream.js should look like this:

UpsertRequest.prototype.loadOrInitializeRecord = function() {
    if(this.internalid) {
        return NetsuiteToolkit.loadRecord(this.record_type, this.internalid);
    } else {
        return NetsuiteToolkit.createRecord(this.record_type);
    }
}

I'm still getting the following error, even though the record gets updated - I'm trying to figure out what the issue is but no luck so far.

{
    "error": {
        "code": "RCRD_UNEDITABLE",
        "message": "Dieser Datensatz kann nicht bearbeitet werden." ("This record can't be edited")
    }
}

@apbit
Copy link

apbit commented Mar 21, 2014

Another thing I changed was this method:
NetsuiteToolkit.setLineItemValue = function(record, sublist_name, field_name, index, value) {
record.setLineItemValue(sublist_name, field_name, index, value);
}

You need to switch the order of field_name and index in the parameters list.

I believe that your body also needs to indicate sublists as an array:
sublists: [{ }], although you might want to remove it if you are not updating any sublists.

I think that's all that I did different, besides using "createRecord" like you indicated.

Regards!

@ephemer
Copy link

ephemer commented Apr 3, 2014

Thanks a lot for your help on this @apbitThe whole netsuite ecosystem is pretty daunting at first

On Fri, Mar 21, 2014 at 11:47 PM, apbit [email protected] wrote:

Another thing I changed was this method:
NetsuiteToolkit.setLineItemValue = function(record, sublist_name, field_name, index, value) {
record.setLineItemValue(sublist_name, field_name, index, value);
}
You need to switch the order of field_name and index in the parameters list.
I believe that your body also needs to indicate sublists as an array:
sublists: [{ }], although you might want to remove it if you are not updating any sublists.
I think that's all that I did different, besides using "createRecord" like you indicated.

Regards!

Reply to this email directly or view it on GitHub:
#14 (comment)

@wilderuncat
Copy link

@ephemer @apbit I found that bug also, and fixed it a slightly different way: #23

@JsbB07
Copy link

JsbB07 commented Oct 21, 2021

I still use this amazing project, so I thought I would post an example of the json that I am sending to Netsuite via python to create new sales orders.

{
"record_data": [
{
"record_type": "salesorder",
"literal_fields": {
"entity": "XXXXX", (Customer ID)
"department": "10", (Department ID)
"otherrefnum": "Test", (Required field)
"memo": "Test",
"message": "Thank you for your business.",
"shipmethod": "XXXXX",
"shipdate": "10/29/2021",
"shipping_rate": "0",
"partner": "XXXX", (Partner ID)
"partnerid": "XXXX" (Partner ID)
},
"sublists": [
{
"name": "item",
"create": [
{
"index": "1",
"data": {
"item": "XXXX", (Internal ID)
"quantity": "2",
"price": "15",
"taxrate": "0"
}
}
]
},
{
"name": "item",
"create": [
{
"index": "2",
"data": {
"item": "XXXX",
"quantity": "6",
"price": "15",
"taxrate": "0"
}
}
]
}
]
}
]
}

I will use this to pickup a csv file, loop through all the rows and generate the json to send to netsuite to create sales orders. Seems to work OK for my purposes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants