CustomData object

Hi,

I trying to use the CustomData object but it returns an error that says: “Object is read only.”. How to solve this?

var priceListService = IoC.Resolve<PriceListService>();
var priceList = priceListService.Get("KUND-1001163")?.MakeWritableClone();

var currentData = (CustomDataTestModel)priceList.CustomData;

if (currentData == null)
    currentData = new CustomDataTestModel();

if (currentData.MyList == null)
    currentData.MyList = new List<Guid>();

currentData.MyList.Add(Guid.NewGuid());

priceList.CustomData = currentData;
priceListService.Update(priceList);
public class CustomDataTestModel : ObjectBase<CustomDataTestModel>
{
    public IList<Guid> MyList { get; set; }
}

Litium version: 7.1

This is a guess but the workflow is usually that you need to clone the read-only objects and then update.

So the pricelist most likely have a method called getWritableClone() use that to get a pricelist that is writable and then commit the changes.

Give it a try!

Also take a look at How to inherit IReadOnly correctly? to see how you should implement the IReadOnly interface in your custom object.

Not sure if this works if I remember correctly also.
I remmeber I had to do like this in order for it to work:

var priceList = priceListService.Get("KUND-1001163");
if (priceList != null)
            {
                priceList = priceList.MakeWritableClone();
            }

There exists a bug about CustomData on pricelists, it sounds like that’s the wall you’re hitting.
https://docs.litium.com/support/bugs/bug_details?id=46318

Hi Nils,

Ah, that seems to be the problem! I will try to update my solution, thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.