Working with multi-line text fields

The formattedTextSupport operation enables or disables formatted text for multi-line text fields. Use true to enable formatted text or false to disable it.

When set to true, the HTML is retrieved from the field. For example:

<p><em><strong>This</strong> is wysiwyg text.</em></p> is returned instead of: This is wysiwyg text.

See Multi-line text field supported fonts and HTML tags for more information.

The attachlist fields contain a list of images in a multi-line text field. The list is an array of CFileAttachment[].

Editing text values

Multi-line text fields can include plain or rich text. All formatting is removed if a field is edited as plain text. Inline images are preserved, but they are appended to the end of the field. Use the formattedTextSupport operation to control how a field is edited.

For example, an issue's Workaround field contains the following formatted text:

Some text here

The text is stored in Helix ALM as:

<p>Some <strong>text</strong> here</p>

The following example shows how to edit this value as plain and rich text.

ttsoapcgi svr;

...

svr.formattedTextSupport(cookie, true);

CDefect dft = svr.getDefectByRecordID(cookie, id, false); // returns "<p>Some <strong>text</strong> here</p>" in the Workaround field

svr.formattedTextSupport(cookie, false);

dft = svr.getDefectByRecordID(cookie, id, false); // returns "Some text here" in the Workaround field

Adding images

Multi-line text fields can contain inline images. The following example shows how to add an image to a field.

// Make sure rich text is enabled

bool richTextEnabled = ttsdk.formattedTextSupport(cookie, true);

 

string filename = "Example1.png";

CFileAttachment file = new CFileAttachment();

file.mstrFileName = filename;

 

System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);

System.IO.BinaryReader reader = new System.IO.BinaryReader(fs);

 

file.mpFileData = reader.ReadBytes((int)fs.Length);

 

reader.Close();

fs.Close();

 

CDefect def = ttsdk.editDefect(cookie, 0, "Defect summary", false);

 

def.workaround =

" <p align=\"center\"><span style=\" font-size:24pt;\">Helix ALMSOAP</span></p><hr />\r\n"

+ "<p><img src=\"Example1.png\" />";

 

def.workaroundInlineAttachList = new CFileAttachment[1];

def.workaroundInlineAttachList[0] = file;

 

ttsdk.saveDefect(cookie, def);

Editing images

You can also edit images in multi-line text fields. The attachment record must exist and be referenced by the multi-line text field value.

For example, an issue's Workaround field contains the following text and image:

Some text and an image

The text and image is stored in Helix ALM as:

<p>Some text and an image <img src="00000001.dat" /></p>

In this example, the image is already saved in Helix ALM and referenced using the archive name of the saved image attachment data, not the filename. The archive name is a unique identifier assigned when the image attachment is uploaded. If attaching a new image, you would use the filename in the img tag and Helix ALM matches it to the attachment record with the same filename.

The following example shows how to upload an image to an issue's Workaround field.

ttsoapcgi svr;

...

svr.formattedTextSupport(cookie, true);

CDefect dft = new CDefect();

// The workaround value references the image by the full path name

dft.workaround = "<p>Some text and an image <img src=""C:\SomeFolder\fileimage.png"" /></p>";

// In the workaround attachment list, the filename must match the referenced name

dft.workaroundInlineAttachList = new CFileAttachment[1];

dft.workaroundInlineAttachList[0] = new CFileAttachment();

dft.workaroundInlineAttachList[0].m_strFileName = "C:\SomeFolder\fileimage.png"";

dft.workaroundInlineAttachList[0].m_pFileData = <the file's data>;

// The issue is added with the inline attachment in the Workaround field

svr.addDefect(cookie, dft);

File data for inline images in multi-line text fields and file attachments is stored in the m_pFileData member of the CFileAttachment object as a Base64-encoded string. The SOAP script or application must encode the image or attachment file data. To display the data, it must be decoded using an implementation of Base64 for the programming language you are using. For example, in .NET, you can use System.Convert.ToBase64String() to encode the binary data for a file attachment or inline image and then store the result in the m_pFileData member when adding a new attachment. You can use System.Convert.FromBase64String() to convert m_pFileData from Base64 to the original binary data for the file so it can be displayed, saved to a file, or used in another way.

When retrieving the issue, the Workaround field value is updated with the archive name, as shown in the following example.

ttsoapcgi svr;

...

svr.formattedTextSupport(cookie, true);

CDefect dft = svr.getDefectByRecordID(cookie, id, false);

// The workaround value references the image archive name

Console.WriteLine(dft.workaround); // Prints: "<p>Some text and an image <img src=""00000001.dat" /></p>"

// In the workaround attachment list, the archive name matches the referenced name

Console.WriteLine(dft.workaroundInlineAttachList[0].m_strArchiveName); // Prints: "00000001.dat"

// The attachment record retains the original file name

Console.WriteLine(dft.workaroundInlineAttachList[0].m_strFileName); // Prints: "fileimage.png"

After an image attachment is saved as an archive, the file data is not returned unless explicitly requested. To retrieve an inline image, the get or edit request must have the include attachment data flag set and formatted text support must be enabled. For example:

ttsoapcgi svr;

...

svr.formattedTextSupport(cookie, true);

// Returns archive data

svr.getDefectByRecordID(cookie, id, true);

// Will not return archive data

svr.getDefectByRecordID(cookie, id, false);

svr.formattedTextSupport(cookie, false);

// Will not return archive data

svr.getDefectByRecordID(cookie, id, true);

// Will not return archive data

svr.getDefectByRecordID(cookie, id, false);