# CustomData object

**URL:** <https://forum.litium.com/t/customdata-object/1111>\
**Category:** Questions\
**Created:** [September 20, 2019, 3:28pm UTC](https://forum.litium.com/t/customdata-object/1111 "2019-09-20T15:28:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [September 20, 2019, 3:28pm UTC](https://forum.litium.com/t/customdata-object/1111/1 "2019-09-20T15:28:57Z")

</div>

Hi,

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

```auto
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);

```

```auto
public class CustomDataTestModel : ObjectBase<CustomDataTestModel>
{
    public IList<Guid> MyList { get; set; }
}

```

Litium version: 7.1

---

<div class="post-metadata">

**Author:** ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)\
**Post date:** [September 21, 2019, 10:58am UTC](https://forum.litium.com/t/customdata-object/1111/2 "2019-09-21T10:58:17Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [September 23, 2019, 4:39am UTC](https://forum.litium.com/t/customdata-object/1111/3 "2019-09-23T04:39:49Z")

</div>

Also take a look at [How to inherit IReadOnly correctly?](https://forum.litium.com/t/how-to-inherit-ireadonly-correctly/1102) to see how you should implement the `IReadOnly` interface in your custom object.

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [September 23, 2019, 7:25am UTC](https://forum.litium.com/t/customdata-object/1111/4 "2019-09-23T07:25:16Z")

</div>

> [@magnus.bolling](#):
>
> var priceList = priceListService.Get(“KUND-1001163”)?.MakeWritableClone();

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

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

```

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [September 23, 2019, 11:11am UTC](https://forum.litium.com/t/customdata-object/1111/5 "2019-09-23T11:11:12Z")

</div>

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](https://docs.litium.com/support/bugs/bug_details?id=46318)

---

<div class="post-metadata">

**Author:** ![magnus.bolling](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/magnus.bolling/32/222_2.png) [@magnus.bolling](https://forum.litium.com/u/magnus.bolling)\
**Post date:** [September 25, 2019, 11:50am UTC](https://forum.litium.com/t/customdata-object/1111/6 "2019-09-25T11:50:12Z")

</div>

Hi Nils,

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [October 23, 2019, 11:52am UTC](https://forum.litium.com/t/customdata-object/1111/7 "2019-10-23T11:52:30Z")

</div>

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