hi, i'm trying to update matrix item with all it's...
# suitescript
d
hi, i'm trying to update matrix item with all it's children, i got error on saving one of the child. this is the error message DUP_ITEM","message":"Uniqueness error - there is already an item with that name or name/parent combination. i have created a saved search filter by Name, and i can confirm there is no duplicate Name, any idea why i got that error and how to fix this ?
p
make sure to look for inactive records as well
b
make sure that the combination of matrix field values are unique as well
d
@Peter Bertelsen i have confirmed there is no inactive item
@battk yes, i have confirmed that as well, we have no duplicate combination of matrix option, since for this item we only have 1 options which is Color, and all 3 children has different colors
but when i try to update the 1st child, i got the above error
b
What does the code look like
d
give me a sec
this is a snippet of my code, i have removed some unrelated lines
Copy code
itemRecord = record.load({
    type: 'serializedinventoryitem',
    id: childrenId,
});

itemRecord.setValue({
    fieldId: 'parent',
    value: parentId,
});

itemRecord.setValue({
    fieldId: 'matrixtype',
    value: 'CHILD',
});

itemRecord.setText({
    fieldId: 'matrixoptioncustitem_matop_color',
    text: ['Blue'],
});

itemRecord.save();
basically i load the child record, set the parent, set matrixtype = Child, then set the color matrixoption to Blue, then save
b
you might get some weirdness if you are updating an item to be a matrix, thats not something that can normally be done via the ui
otherwise i would recommend setValue over setText
and explicitly setting the name, matrix items have naming schemes that you may need to overwrite
otherwise make sure that the matrix parent has Blue set as a value for custitem_matop_color
d
right, i also realized that it's not right if we set Exsiting item to be matrix subitem, the Subitem of works, but it doesn't show under the parent sublist
and yes, right, this happens to "Existing Item" which i try to set as Submatrix item
b
i wouldnt recommend the updating route, create new items
doing things you cant do in the ui only leads to trouble
d
right, agree. But i have an issue here, since the creation / updating of item comes from external party, which is a website built with Magento, i have to make changes on it to not allow user to do the assignment of "existing item" to Matrix
btw FYI, the above script, if i remove the
Copy code
itemRecord.setValue({
    fieldId: 'matrixtype',
    value: 'CHILD',
});
it works, the item updated successfully
b
it might update the item, but i doubt that makes it a matrix item
i would suspect you can only make it a matrix child on create
d
yes, right
i hope to see this enhancement on the next release