Copy Media Object

Sachinkl

Member
Hi,

When coping a records in an interactive application, is it possible to also copy the media object information?

Thanks,
Sachin
 
If you build a C Business function to copy the media object record in F00165 I think it should work. Doing it in C is your only hope. Fetch the record, change the TXKY value, insert the record. The only unknown I have is whether the MO Blob in TXFT will insert correctly. Since you are not going to manipulate it and will leave it untouched in the data structure I think it might work.

I just noticed that there are some examples of standard functions that do this. I haven't looked at them to see what they do.
 
We copy a template MO when adding a Sales Order in P4210, and display it for the user to change it, but I guess it should work for copying a record, too.
 
We created a system that allows a user to set up a Custom Media Object using a Generic Media Structure with Address Number, B/P, Media Type and Company as it's keys. Then when an order is entered for that customer, we look to the F00165 for a Media object of our custom type with those keys. (i.e. 'O' for Order Attachment, 'D' for a Detail Attachment, 'T' for transportation, etc.)

This function checks for the Custom Media Object, then if found, copies it to the new Media Object for that specific order.
Here is an excerpt from one of the internal functions that will create a Header Attachment for a Custom one if it exists. It is somewhat self explanatory if you read C. All of this was copied from existing functionality within... It should help you understand how to copy a Media Object in C.
PS - There is a way to do it using system functions but this is much more fun...
smile.gif


/**************************************************************************
* Function: I55CUSAT_AttachCustomHeaderMediaObject
*
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************/
ID I55CUSAT_AttachCustomHeaderMediaObject (LPBHVRCOM lpBhvrCom, LPDSD55CUSATA lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
ID idReturnValue = JDEDB_PASSED;

/************************************************************************
* Declare structures
************************************************************************/

DSGT4201A dsGT4201A = {0};
DSGT5940305A dsGT5940305A = {0};

/************************************************************************
* Declare pointers
************************************************************************/

LPCSTR szLang = " ";
LPSTR pStringKey = (LPSTR)NULL;
LPF0016D lpHeaderMediaObject = (LPF0016D)NULL;

/************************************************************************
* Main Processing
************************************************************************/

memset((void *)(&dsGT4201A), (int)('\0'), sizeof(DSGT4201A));
memset((void *)(&dsGT5940305A), (int)('\0'), sizeof(DSGT5940305A));


MathCopy (&dsGT5940305A.mnAddressNumberShipTo, &lpDS->mnAttachmentShipTo);
strcpy (dsGT5940305A.szCompanyKeyOrderNo, lpDS->szAttachmentCompany);
strcpy (dsGT5940305A.szCostCenter, lpDS->szAttachmentCostCenter);
strcpy (dsGT5940305A.szIdentifier2ndItem, lpDS->szAttachment2ndItem);
dsGT5940305A.cCustomerCommentTemplate = lpDS->cAttachmentType;

/* Build the key string for the Custom Media Object */
pStringKey = AllocBuildStrFromDstmplName(NULL, "GT5940305A", &dsGT5940305A);
pStringKey = StripKey (pStringKey);

/* Get the GT5940305A Media Object if it exists */
idReturnValue = JDEGTAllocFetch (lpBhvrCom->hEnv,"GT5940305A", pStringKey, szLang, &lpHeaderMediaObject);

if (idReturnValue != JDEDB_PASSED)
{
strcpy (dsGT5940305A.szCostCenter, " ");

/* Build the key string for the Custom Media Object without using the Cost Center*/
pStringKey = AllocBuildStrFromDstmplName(NULL, "GT5940305A", &dsGT5940305A);
pStringKey = StripKey (pStringKey);

/* Get the GT5940305A Media Object if it exists */
idReturnValue = JDEGTAllocFetch (lpBhvrCom->hEnv,"GT5940305A", pStringKey, szLang, &lpHeaderMediaObject);

if (idReturnValue == JDEDB_PASSED)
{
MathCopy (&dsGT4201A.mnDocumentorderinvoicee, &lpDS->mnOrderNumber);
strcpy (dsGT4201A.szOrdertype, lpDS->szOrderType);
strcpy (dsGT4201A.szCompanykeyorderno, lpDS->szOrderCompany);

/* Build the key string for the New Order */
pStringKey = AllocBuildStrFromDstmplName(NULL, "GT4201A", &dsGT4201A);
pStringKey = StripKey (pStringKey);

/* Create the New Order Media Object */
strcpy (lpHeaderMediaObject->gdobnm, "GT4201A");
strcpy (lpHeaderMediaObject->gdtxky, pStringKey);

idReturnValue = JDEGTAdd(lpBhvrCom->hEnv, lpHeaderMediaObject, NULL);

}

}
else
{
MathCopy (&dsGT4201A.mnDocumentorderinvoicee, &lpDS->mnOrderNumber);
strcpy (dsGT4201A.szOrdertype, lpDS->szOrderType);
strcpy (dsGT4201A.szCompanykeyorderno, lpDS->szOrderCompany);

/* Build the key string for the New Order */
pStringKey = AllocBuildStrFromDstmplName(NULL, "GT4201A", &dsGT4201A);
pStringKey = StripKey (pStringKey);

/* Create the New Order Media Object */
strcpy (lpHeaderMediaObject->gdobnm, "GT4201A");
strcpy (lpHeaderMediaObject->gdtxky, pStringKey);

idReturnValue = JDEGTAdd(lpBhvrCom->hEnv, lpHeaderMediaObject, NULL);

}

FreeStrFromDstmpl(pStringKey);
JDEGTFree (NULL, lpHeaderMediaObject);

return (idReturnValue);
}
/* End I55CUSAT_AttachCustomHeaderMediaObject */
 
Back
Top