Item Picture- Webservice

 

Hey Friends,

I was just working on an assignment where I got the need of the customer like they want the Item Picture via web service. Another validation they put in was they don’t want the item picture to be saved on any particular directory instead they want on fly.

So now in standard NAV 2018 Item picture data-set has been changed from Blob to Mediaset so it was then added challenge. We need to convert the picture into streams and bytes and then we can send this over service but how to convert it into bytes. Converting Blob we all are well experienced but what about Mediaset.

There’s a new virtual table which Microsoft has introduced to maintain this identity in Blob which is Tenant Media. The reason why Microsoft did so is now we have the capability to add multiple pictures for an item.

So here is the piece of code how we are suppose to do this.

//RWN
Item.GET(ItemNo);
IF Item.Picture.COUNT = 0 THEN
EXIT(”);

TenantMedia.GET(Item.Picture.ITEM(1));
TenantMedia.CALCFIELDS(Content);
IF TenantMedia.Content.HASVALUE THEN BEGIN
CLEAR(PictureText);
CLEAR(PictureInStream);
TenantMedia.Content.CREATEINSTREAM(PictureInStream);
TempBlob.DELETEALL;
TempBlob.INIT;
TempBlob.Blob.CREATEOUTSTREAM(PicOutStream);
COPYSTREAM(PicOutStream,PictureInStream);
TempBlob.INSERT;
TempBlob.CALCFIELDS(Blob);
PictureText.ADDTEXT(TempBlob.ToBase64String);
END;
//RWN

Return this Picturetext in Web-service and they have to convert it from Base 64 string, they will have the real image.

Item Record Item
TenantMedia Record Tenant Media
PictureText BigText
PictureInStream InStream
TempBlob Record TempBlob

CHEERS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s