RE: REST item sublist replace on invoice, cant add new item

I have the starting values of item collection on invoice:

{ 
     "item" : { 
          "items" : [ 
               { "line" : 1, (other values) }, 
               { "line" : 2, (other values) } 
     } 
}

If a user were to remove line 2 I can patch as follows:

PATCH …/invoice/100?replace=item

{

"item" : {

"items" : [

{ "line" : 1, (other values) }

}

}

This works and removes the second line.
But if the user made a mistake and wants to add the line back…

PATCH …/invoice/100?replace=item

{

"item" : {

"items" : [

{ "line" : 1, (other values) },

{ "line" : 2, (other values) }

}

}

This returns the error “Error while accessing a resource. The record has been deleted since you retrieved it.”

I thought maybe the system was right, I did remove line 2 so lets try…

PATCH …/invoice/100?replace=item

{

"item" : {

"items" : [

{ "line" : 1, (other values) },

{ "line" : 3, (other values) }

}

}

And I still get the error “Error while accessing a resource. The record has been deleted since you retrieved it.”

I thought, “okay, well, lets leave line empty and let NetSuite assign it.”

PATCH …/invoice/100?replace=item

{

"item" : {

"items" : [

{ "line" : 1, (other values) },

{ "line" : null, (other values) }

}

}

but now I get the error, “Invalid value for the resource or sub-resource field ‘line’. Provide a valid value.”

Clearly removing the lines works as per the documentation:
Keyed sublist lines are updated if the key matches, other lines are removed, and unmatched lines from the request are created as new.

The issue, however is that last statement. I can’t seem to get the lines added back.

Add Comment
1 Answers
Best answer

Hi,

What happens if you omit line from the line to be added?

Thanks,

Chris

Intermediate Answered on March 7, 2023.

It returns as “No Content” indicating a successful update. Maybe I don’t understand.

 

Given the invoice starts as:


{     “item” : {          “items” : [              { “line” : 1, (other values) },              { “line” : 2, (other values) }     }}

 

If I patch as follows:

PATCH …/invoice/100?replace=item


{     “item” : {          “items” : [               { “line” : 1, (other values) }     }}

 

it works, return “NO CONENT” and removes the second line.   If I resubmit that same PATCH, it just returns with “NO CONTENT” indicating a success.

on March 7, 2023.

Hi Brian, I meant, what happens if you do this:

{    "item" : {    "items" : [        { "line" : 1, (other values) },        { (other values) }    ]} 

on March 7, 2023.

You are brilliant!  That works.  It seems so odd I have to strip out the line field.

 

Thanks!

on March 7, 2023.

It is odd but glad it works!

on March 7, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.