# How to update DraftBlockFieldData?

**URL:** <https://forum.litium.com/t/how-to-update-draftblockfielddata/1280>\
**Category:** Questions\
**Tags:** litium-7\
**Created:** [January 14, 2020, 2:45pm UTC](https://forum.litium.com/t/how-to-update-draftblockfielddata/1280 "2020-01-14T14:45:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hjalmar](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@hjalmar](https://forum.litium.com/u/hjalmar)\
**Post date:** [January 14, 2020, 2:45pm UTC](https://forum.litium.com/t/how-to-update-draftblockfielddata/1280/1 "2020-01-14T14:45:37Z")

</div>

I am trying to update a Block’s field value from an API Controller. I have succeded to update the production data (_Blocks.BlockFieldData_-table) but the changes are not visible in Backoffice. I understand Backoffice is working with _Blocks.DraftBlockFieldData_-table and data is copied to _Blocks.BlockFieldData_-table at publish.

**Q: How do I update the DraftBlockFieldData?**

According to [this](https://forum.litium.com/t/getting-some-insight-of-page-field-data/709/2) answer, the equivalent problem for _DraftPageFieldData_ is soloved with implementing _IReadOnly_ on the MultifieldItem object. I did try this, but without success. Not sure if my implementation is enough.

**Function:**

```
protected override void ProcessBlock(BlockStyle item)
{
    var block = _blockService.Get(item.Id).MakeWritableClone();
    var styleList = new List<MultiFieldItem>();
    var multiFieldItem = new MultiFieldItem();

    multiFieldItem.Fields.AddOrUpdateValue(CustomBlockFieldNameConstants.StartColumnX, "*", item.XStart);
    multiFieldItem.Fields.AddOrUpdateValue(CustomBlockFieldNameConstants.EndColumnX, "*", item.XEnd);

    styleList.Add(multiFieldItem);
    block.Fields.AddOrUpdateValue(CustomBlockFieldNameConstants.StyleXLarge, "*", styleList);
    
    using (Solution.Instance.SystemToken.Use())
    {
        _blockService.Update(block);
    }
}

```

**Object equivalent to CustomBlockFieldNameConstants.StyleXLarge:**

```
public class BlockStyle: IAutoMapperConfiguration, IViewModel, IReadOnly
{
    public string StartColumnX { get; set; }
    public string EndColumnX { get; set; }

    public bool IsReadOnly => false;

    public void MakeReadOnly()
    { }

    public object MakeWritableClone()
    {
        return null;
    }

    [UsedImplicitly]
    void IAutoMapperConfiguration.Configure(IMapperConfigurationExpression cfg)
    {
        cfg.CreateMap<MultiFieldItem, BlockStyle>()
            .ForMember(x => x.StartColumnX,
                m => m.MapFrom(c => c.Fields.GetValue<string>(CustomBlockFieldNameConstants.StartColumnX)))
            .ForMember(x => x.EndColumnX,
                m => m.MapFrom(c => c.Fields.GetValue<string>(CustomBlockFieldNameConstants.EndColumnX)));
    }
}

```

Litium version: 7.3.1-patch-1911150957

---

<div class="post-metadata">

**Author:** ![ton.nguyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ton.nguyen/32/989_2.png) [@ton.nguyen](https://forum.litium.com/u/ton.nguyen)\
**Post date:** [January 14, 2020, 8:41pm UTC](https://forum.litium.com/t/how-to-update-draftblockfielddata/1280/2 "2020-01-14T20:41:39Z")

</div>

To update draft data, you should use DraftBlockService instead, to get a DraftBlock and again use that service to update the DraftBlock.

---

<div class="post-metadata">

**Author:** ![ton.nguyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ton.nguyen/32/989_2.png) [@ton.nguyen](https://forum.litium.com/u/ton.nguyen)\
**Post date:** [January 14, 2020, 8:43pm UTC](https://forum.litium.com/t/how-to-update-draftblockfielddata/1280/3 "2020-01-14T20:43:53Z")

</div>

If you are uncertain about the IReadOnly implementation, I would suggest to try updating the built-in field type, short text for example, to make sure you use the right service to update draft data. Then when it works, try with your custom field.

---

<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:** [February 11, 2020, 8:43pm UTC](https://forum.litium.com/t/how-to-update-draftblockfielddata/1280/4 "2020-02-11T20:43:59Z")

</div>

Closed on February 11, 2020, 8:43pm UTC

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