Skip to main content
Business Central forum
Suggested answer

How to de-reference Media fields?

editSubscribe (1) ShareShare
ReportReport
Posted on by 171
Hello folk!
This is my first time playing around with Media Type instead of blog and I'm facing a bit of a challenge.
I have two tables - Location Master with a Media Type field storing QR Codes and Sales Header where the QR Code is to be referenced.
When the Location is set on the Sales Header, I can use the Validate trigger to set the /Location QR Code/ field of the Sales Header by assigning the /QR Code/ of the Location record.
However, when the time comes to change the Location Code on the Sales Header and I try to de-reference the /Location QR Code/ of the Sales Header, I end up deleting the QR Code's data from the main /Location/ record itself.
If I use the Import/Export stream methods that creates additional tenant media records which uses up more space than necessary.
I read in the Microsoft docs that as long as the Tenant Media record is being referenced somewhere, it does not get deleted so I was hoping that would work out.
Also, this blog here suggests that when we assign a Media field to another, then both reference the same record in the Tenant Media table.
I want to know how to dereference one of them.
Any direction is highly appreciated!
Categories:
Attachments
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 60,007 Super User on at
    How to de-reference Media fields?
    If it is MediaSet Data Type, you can try the following mehtod, but Media data type does not. . . .
    MediaSet.Remove(Guid) Method
  • RahulBansode Profile Picture
    RahulBansode 171 on at
    How to de-reference Media fields?
    Hi Yun Zhu,
     
    I have tried the clear(Rec.MediaField) function as well however it ends up deleting the media from both the tables i.e. the Tenant Media record itself is deleted.
    I also tried reassigning it to a uninitialized media field (Rec.MediaField = TempRec.MediaField) but that also erased the data from both the tables which is rather unexpected.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 60,007 Super User on at
    How to de-reference Media fields?
    Hi, have you tried using Clear method?
    For example,
    Clear(Rec.Picture);
     
    Hope this helps.
    Thanks.
    ZHU
     
  • RahulBansode Profile Picture
    RahulBansode 171 on at
    How to de-reference Media fields?
    Hi there!
    My goal is to prevent the deletion of the Tenant Media record and simply de-reference it from one of the records without affecting the other,
    Orphaned Media records are not really relevant here.
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 2,786 Super User on at
    How to de-reference Media fields?

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,126 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,646 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans