Has anyone ever used the Commerce API order method...
# suitecommerce
k
Has anyone ever used the Commerce API order method setItemOptions(itemlineid, optionMap) and gotten it to work. I don’t understand what the documentation in SuiteCommerce Developer for the optionMap argument is asking for. I have tried different data structures and none of them work. The values in the custom option fields are never updated. I have tried the following values for optionMap: {options: [{id: custom_field_id, value: some_value}]} {options: {custom_field_id: some_value}} I have also tried leaving out the {options: …} part, but I get an error that says “options” is required. The documentation says “optionMap [required] {Array of Item Option ID value pairs}” I am left wondering if this method works at all. Any ideas?
p
Copy code
var option_map = {
    custcol_personalized: 'T'
 }; 
order.setItemOptions(lineid, option_map);
you might want to experiment with sending all the previous set options and not just the one you want to change.
k
@PabloZ, thanks. Just to double check you can confirm that this works? I hate to ask, but I thought I tested this, but I am not sure what my data structure looked like when I left out the {options: …}
I’ll retest now. Thank you so much for the feedback. I have spent hours trying to get this to work.
@PabloZ, you are a life saver. It worked. This is huge. Thanks a ton.
p
Know the feeling. Commerce API is so quirky and could use some better docs! Glad it worked!
k
OMG. You are a life saver. I ran other test with a list/record custom transaction line field and it worked. I discovered you do not need to include all of the existing item options and line fields when you update the item options. The option_map only needs to contain the fields you want to change.
I must say that I truly dislike the Commerce API and wish I had full access to SuiteScript with the default permissions set as appropriate for web store users.
p
I think that's something that we will see in the next few years coupled to SuiteScript 2.0 refactoring too.
d
@PabloZ is the man!
@Keith Fetterman you could give your service files elevated permissions. Moreover most SuiteScript APIs should be usuable.