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...
/**************************************************************************
* 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 */