I am trying to use the extensibility API method, a...
# suitecommerce
k
I am trying to use the extensibility API method, addLine. the method works fine, However I would like to insert data into a custom field when doing it and cant seem to make it work. I set up a custom transaction item option field called custcol_subscription_frequency I also tried transaction line fields, checked the applies to boxes for sale and web... Then I am trying to run the following code which I am not even sure is correct any more...
container.getComponent('Cart').addLine({
line: {
quantity: '2',
item: {
internalid: '840'
},
options: [
{
cartOptionId: 'custcol_subsscription_frequency',
value: "2"
}
]
}
}).then(data => {
console.log('Item added', data);
Backbone.history.navigate('/cart', {trigger: true});
}).fail(error => {
console.error('There was an error adding the item', error);
alert('There was an error adding the item, see console for details.');
});
When I run this code block the item is added to the cart, but the option is not set. any help is much appreciated!
s
Is custcol_subsscription_frequency spelled correctly?
Because that looks like a typo to me
k
LOL Sorry, it is correct, I think just in the last test I fat fingered and thats what I coppied
when I run getlines() I can see the custom field is showing up in item.extras.options
s
OK, well other than that the only obvious things are that quantities should be integers and not strings
k
but no matter what I try I can seem to set a value and it does not show up under the root options block
s
And I'm assuming the custom column is a text field?
k
it is
s
And it's not expecting an integer and not a string either?
k
Its set as a freeform text so I would assume it does not matter?
s
OK
Well, I don't know then. As I said, the quantity should be an integer. I've seen having that as a string messing up other things without error; it's farfetched but it could be because of that.
k
Okay, Ill give it a shot
nope, no difference...
s
Other than that, this is the code that I have for my test site that meets similar conditions to what your code is trying to do:
Copy code
container.getComponent('Cart').addLine({
    line: {
        internalid: '3899',
        quantity: 1,
        item: {
            internalid: '3899'
        },
        options: [
            {cartOptionId: 'custcol1', value: {internalid: 'Test'}},
            {cartOptionId: 'custcol_gen_color', value: '3'},
            {cartOptionId: 'custcol_gen_size', value: '5'}
        ]
    }
})
Perhaps monkeying it to fit your site might work
k
But you think the syntax in general looks correct?
s
Apart from the arrow functions that we say you shouldn't use, yes 🙃
😃 1
😂 1
k
Great, thanks so much for the advice...
k
@Kirk Taylor I know Steve has mentioned in the past the quantity property type is number. I've had that issue before, trying to set quantity with a string and having inconsistent results.
k
I have changed it to integer.... Still no difference
I will leave it that way though
what're the details in your error log?
s
Oh that's one thing that could be wrong but is present in my code example: you need to pass in an object as the value of the the option
Copy code
options: [
  {cartOptionId: 'custcol_subscription_frequency', value: {internalid: '2'}}
]
Note my example:
Copy code
options: [
            {cartOptionId: 'custcol1', value: {internalid: 'Test'}}
        ]
👍 1
k
Still no luck 😐 Ive set up custom fields 100 times but never with 2020+ and never tried to set with the extensibility api.
OOOhhh, I got it working,
s
Oh yeah? How?
k
Well, I have done so much testing who knows what I jacked up so I realized I was testing with a transaction line field instead of a transaction line option field, so I recreated the correct field along with your passing the value as an object
Basically your code fixed it, I just needed to recreate the field
s
netsuite halo
🤣 1