• Introducing Dark Mode! Switch by clicking on the lightbulb icon next to Search or by clicking on Default style at the bottom left of the page!

E9.1 MO attachment append for RTF format

Rich@13

Member
Hi,

Can you please suggest how to merge two RTF or HTML formatted text attachments in JDE using a business function.

Thanks in advance!!
 

Larry_Jones

Legendary Poster
I'm not saying there isn't one, but I'm unaware of any BSFN that will do this for you.

What is your use case / issue that your are terying to solve?
 

Rich@13

Member
Hi Larry,

We are doing mass update of Text type Media object attachment for multiple objects, Where we have to get the previously stored MO attachment from F00165 table and append it with the latest MO attachment text and while doing this we should also maintain the format of the text.

Thanks
 

craig_welton

Legendary Poster
You can use the C media object APIs to do this. Fetch the current text, allocate a buffer the size of the current text plus the size of the new text. Concat the current and new text into the buffer and then save the MO. I'm not sure how things would look if you have a mix of RTF and HTML.

Craig
 

Rich@13

Member
Hi Craig,
Thanks for the reply, I have tried this approach but it's giving me plain text in the result.
Although I have passed HTML formatted MO text value to the bsfn. Also I have used GetGenericTextName API to get the previously stored text.
 

Larry_Jones

Legendary Poster
So how I've dealt this kind of stuff before (not same issue you have but close) is to build some tools in the Database.
1. A function A that converts the IMAGE data type to nVarchar(max) - cast(cast(@TXFT as varbinary(max)) as nvarchar(max))
2. Create a Stored Procedure B that converts the concatenated nvarchar(max) back to binary and updates the original F00165
3. Create a view/query Against F00165 that narrows down the data to text for the Object(s) you want to change - use Function A to convert to nvarchar(max)
4. Build a TSQL script with a Fetch Cursor Loop in it that reads the HTML text as a string, appends your new HTML Text, then calls B with the key fields and HTML string

You may need to do some trimming and add some transition HTML between the two pieces.
 

Rich@13

Member
Are you passing FALSE as the last parameter? That should stop it from converting to plain text.


Hi Craig,

I am using the following code to merge the attachments. But it's converting the stored HTML attachment to plain text.



/* An existing attachment exists, concatenate the new text */
pNewText = (PJSTR) jdeAlloc(COMMON_POOL, ( jdeStrlen(lpDS->szMediaObjectText) + jdeStrlen(pText) + 8) * sizeof(JCHAR),MEM_ZEROINIT );
jdeSprintf(pNewText, _J("%ls%ls\n"), lpDS->szMediaObjectText, pText);
}

/* Update the attachment for the invoice */
if (ModifyGenericTextName(_J("GT4801"), &dsGT4801, pNewText) != JDEDB_PASSED)
{
lpDS->cERRORFlag= _J('1');
}
 

Kim Schmidt

Active Member
Rich, I suspect that the jdeSprintf() is internally extracting the plain text from the HTML. Perhaps using jdeStrncat() instead of jdeSprintf() would work fot you, like this:
pNewText = (PJSTR) jdeAlloc(COMMON_POOL, ( jdeStrlen(lpDS->szMediaObjectText) + jdeStrlen(pText) + 8) * sizeof(JCHAR),MEM_ZEROINIT );
jdeStrncpy(pNewText, lpDS->szMediaObjectText, DIM(pNewText))
jdeStrncat(pNewText, pText, DIM(pText));
 

craig_welton

Legendary Poster
Hi Craig,

I am using the following code to merge the attachments. But it's converting the stored HTML attachment to plain text.



/* An existing attachment exists, concatenate the new text */
pNewText = (PJSTR) jdeAlloc(COMMON_POOL, ( jdeStrlen(lpDS->szMediaObjectText) + jdeStrlen(pText) + 8) * sizeof(JCHAR),MEM_ZEROINIT );
jdeSprintf(pNewText, _J("%ls%ls\n"), lpDS->szMediaObjectText, pText);
}

/* Update the attachment for the invoice */
if (ModifyGenericTextName(_J("GT4801"), &dsGT4801, pNewText) != JDEDB_PASSED)
{
lpDS->cERRORFlag= _J('1');
}
Where is the code to retrieve the existing attachment?
 

Larry_Jones

Legendary Poster
Thanks Craig, It's working now.
It's creating some extra space between the text , Can you please suggest how to remove that extra lines between the text.
Actually the JDE Media Object routines have a tendency to create those trailing spaces (and sometimes more). Users may also create blank lines at the end.
 
Top