Write to or Retrieve from Media Object – Text

Media Object Text html editorMedia Objects and Imaging is a wonderful feature JD Edwards has which enables you to attach useful information to an application, including information that might currently exist as a paper-based document. Attachments which can be used are Text, Images, OLE, JDE Shortcuts, or URL’s. All these media objects are stored in F00165 table.

The Text feature in the media object includes a word processor that lets you create, view, edit, and delete notes. When you create a text attachment, you can also set up templates. You can use templates to create a format for a frequently used media object.
If from an application, you have Media Object Controls to be shown, or you can use System functions to Set Text, Get Text, or Edit the Media Object using the MO Datastructures (GT****) for that particular key. But all these pop up the Media Object Editor up on screen.

If you do not need to show the Media object editor while saving a Text attachment or say, from a UBE; it would be not so easy. Because, the Text is stored as a BLOB in F00165. So… No direct Inserts would work.

There are JDE provided API’s do do the needful here.

  1. jdeGTAddUpdate_TextKeyStr
  2. jdeGTGet_GenericTextKeyStr

AddUpdate TextKeyStr

JDERTN(JDEDB_RESULT) JDEWINAPI jdeGTAddUpdate_TextKeyStr(
PJSTR szObjectName,
PJSTR pszMOKeyStr,
LPMODATA pMOData,
long lTotalRec
);

Following would be how we would Insert a Text Attachment

WriteToMOText (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5500165 lpDS)
{
	long		lTotalRec = 0;
	int			iSequenceNum = 0;

	JDEDB_RESULT	JDBReturn = JDEDB_PASSED;
	//---------------------------------------
	//Initialize Media Object Structure
	LPMODATA	pMOData = NULL;

	/* Populate the pMOData for the new record  */
	lTotalRec = 1;

	pMOData = jdeAlloc(COMMON_POOL, 255*sizeof(LPMODATA), MEM_ZEROINIT);

	pMOData->nSeq = iSequenceNum;
	pMOData->nMOType = 0;
	jdeStrcpy (pMOData->szUser, _J(" "));

	jdeStrcpy (pMOData->szItemName, lpDS->szGenericTextItemName_GTITNM);/*Name of Text Attachment - Ideally "Text1"*/
	jdeStrcpy (pMOData->szQueueName, _J(" "));
	jdeStrcpy (pMOData->szFileName, _J(" "));

	pMOData->pData = jdeAlloc(COMMON_POOL, 30001, MEM_ZEROINIT);
	jdeStrcpy (pMOData->pData, lpDS->szMediaObjectText_MOTEXT);/*Text to be written in the MO Text attachment*/

	JDBReturn = jdeGTAddUpdate_TextKeyStr(lpDS->szObjectName_OBNM, lpDS->szKey_MOTXKY, pMOData, lTotalRec);
	if (JDBReturn != JDEDB_PASSED)
	{
		jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("164F"), (LPVOID) NULL);
		return (ER_ERROR);
	}
}

RetrieveMO Text

JDERTN(JDEDB_RESULT) JDEWINAPI jdeGTGet_GenericTextKeyStr(
PJSTR szObjectName,
PJSTR pszMOKeyStr,
int nSeq,
LPMODATA pMOData,
long lTotalRec
);

This would be how we would retrieve the MO Text

RetrieveMOText (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N0011B lpDS) 
{
	long	lTotalRec = 0;
	int	iSequenceNum = 0;

	JDEDB_RESULT	JDBReturn = JDEDB_PASSED;
	LPMODATA	pMOData = NULL; //Initialize MO Data structure

	iSequenceNum = lpDS->iSequenceNumber_MOSEQN; /*Sequence would the ordinal number in MO Texts*/

	if (iSequenceNum <= 0)
 	{
 	  jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("164F"), (LPVOID) NULL);
   	  return (ER_ERROR);
	}
 	else
 	{
 	  JDBReturn = jdeGTGet_GenericTextKeyStr (lpDS->szObjectName_OBNM, lpDS->szKey_MOTXKY, iSequenceNum, &pMOData, &lTotalRec);

	  if (JDBReturn == JDEDB_PASSED)
		{
		/* Return the text to the data structure.  */
		  jdeStrcpy (lpDS->szMediaObjectText_MOTEXT, pMOData->pData);
		  jdeStrcpy (lpDS->szGenericTextItemName_GTITNM, pMOData->szItemName);
		}		
		else
		{
		  jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL); 
 		  return (ER_ERROR);
		}
	}
}

Attached are the sample .c, Data structure and ER code for your reference

WriteReadMOText.zip

Ref: PeopleBooks

Leave a Reply