I had read many forums and tried many solutions but nothing has worked till yet.
I had already tried below ways to copy mediaset -
1.) TRANSFERFIELDS & CALCIFIELDS - It does not work for mediaset datatype fields.
2.) Exporting image and trying to import again - Since we work on remote server, while trying to access the image it says that the file path is not found. On the other hand, With Temporary path, it is just not working.
3.) Create RecordRef and FieldRef variables and then transfer the value from one record in other record and then save the reference to the permanent records. It also seems to not working.
I know that to use the same picture for more than one company, I need to create copy in all companies. But I just somehow not able to achieve this.
May be I just do not understand how the table "Tenant Media" & "Tenant Media Set" are connected to each other but I learned it from this link -
http://navisionabeirar.com:49000/help/en/47fb1195-eaa1-4995-9013-5edc28b13132.htmThese are some code snippet that I tried for above points respectively, but none of them working -1.) For Point no. 1 -
Item1. TRANSFERFIELDS(Item2);
Item1.MODIFY(TRUE);
It is not working...
2.) & 3.) For point no. 2 & 3 -
//ToItem.Picture.INSERT(FromItem.Picture.ITEM(1));
//ToItem.MODIFY;
{TenantMedia.GET(FromItem.Picture.ITEM(1));
TenantMedia."Company Name" := '';
TenantMedia.MODIFY;}
//COMMIT;
{CLEAR(TenantMedia2);
TenantMedia2.TRANSFERFIELDS(TenantMedia);
TenantMedia2.ID := CREATEGUID;
TenantMedia2.Height := 200;
//TenantMedia.CALCFIELDS(Content);
//TenantMedia2.Content := TenantMedia.Content;
TenantMedia2."Company Name" := Company.Name;
//----
IF FORMAT(FromTenantMedia) <> '' THEN
IF FORMAT(ToTenantMedia) <> '' THEN BEGIN
ToTenantMedia.SETTABLE(TenantMedia2);
FromTenantMedia.SETTABLE(TenantMedia);
FromTenantMediaField := FromTenantMedia.FIELD(TenantMedia.FIELDNO(Content));
ToTenantMediaField := ToTenantMedia.FIELD(TenantMedia2.FIELDNO(Content));
ToTenantMediaField.VALUE := FromTenantMediaField.VALUE;
ToTenantMedia.GETTABLE(TenantMedia2);
END;
//----
TenantMedia2.INSERT;
TenantMediaSet2.RESET;
TenantMediaSet2.ID := CREATEGUID;
TenantMediaSet2."Media ID".IMPORTFILE(TenantMedia2.ID,'','');
TenantMediaSet2.INSERT;
//COMMIT;
ToItem.Picture.INSERT(TenantMediaSet2.ID);
ToItem.MODIFY;}
//
//TenantMediaSet.SETRANGE(ID,FromItem.Picture.ITEM(1));
//IF TenantMediaSet.FINDFIRST THEN;
//TenantMediaSet."Media ID".EXPORTFILE('TemporaryFile');
FromItem.Picture.EXPORTFILE('TemporaryFile');
ToItem.Picture.IMPORTFILE('TemporaryFile-1','','image.jpeg');
ToItem.MODIFY;
//ToItem.MODIFY;
{ CLEAR(TenantMediaSet);
TenantMediaSet.SETRANGE(ID,FromItem.Picture.MEDIAID);
IF TenantMediaSet.FINDFIRST THEN
BEGIN
CLEAR(TenantMedia);
IF TenantMedia.GET(TenantMediaSet."Media ID") THEN BEGIN
CLEAR(TenantMedia2);
TenantMedia2.TRANSFERFIELDS(TenantMedia);
TenantMedia2.ID := CREATEGUID;
TenantMedia2.INSERT;
END;
END;
IF TenantMediaSet.GET(FromItem.Picture.MEDIAID,FromItem.Picture.ITEM(1)) THEN
BEGIN
MESSAGE('Tenant Media Set has been found for FROM_ITEM');
CLEAR(TenantMediaSet2);
TenantMediaSet2.TRANSFERFIELDS(TenantMediaSet);
TenantMediaSet2.ID := CREATEGUID;
TenantMediaSet2."Media ID" := TenantMedia2.ID;
//EVALUATE(TenantMediaSet2."Media ID",TenantMedia2.ID);
TenantMediaSet2."Company Name" := Company.Name;
TenantMediaSet2.INSERT; }
//END;
//COMMIT;
//ToItem.Picture.INSERT(TenantMediaSet2.ID);
//ToItem.MODIFY;
May be I have tried just too many ways and then, it is just not working.
PLEASE SUGGEST WHAT SHOULD BE THE ACTUAL WAY OF DOING IT. IF NOT POSSIBLE, KINDLY SUGGEST SOME WORKAROUND AS WE WERE ABLE TO ACHIEVE THIS IN PAST WITH OLDER THAN NAVISION 2017 VERSION, SO WE SHOULD ABLE TO ACHIEVE THIS WITH NEW VERSIONS AS WELL.
Answers
CHANGECOMPANY seems not working on field Picture. Hence, you need to do it in two times:
Check the code in page "Item Picture" (ID 346).
I have wasted so much time for the solution but finally it is done. Only thing I was doing wrong that I deleted the company from Tenant Media table but not from Tenant Media Set
Check the code here, works perfectly fine...
CLEAR(fromguid);
CLEAR(fromitem);
CLEAR(tenenetmediaset);
CLEAR(tenentmedia);
fromitem.GET('LR-E0030');
toitem.CHANGECOMPANY('Notions Trading LLC');
toitem.GET(fromitem."No.");
index :=1;
toitem.Picture.INSERT(fromitem.Picture.ITEM(index));
toitem.MODIFY(TRUE);
IF tenentmedia.GET(fromitem.Picture.ITEM(index)) THEN BEGIN
tenentmedia."Company Name" :='';
tenentmedia.MODIFY;
END;
IF tenenetmediaset.GET(toitem.Picture.MEDIAID,fromitem.Picture.ITEM(index)) THEN BEGIN
tenenetmediaset."Company Name" := '';
tenenetmediaset.MODIFY;
END;