Knowledgebase

Search:     Advanced search

Editing Multi-Line Text Fields with the TestTrack SDK

Article ID: 481  |  Last updated: 23 Dec, 2014

The following information is provided to help you edit formatted text and inline attachments in multi-line text fields using the TestTrack SDK.

Editing text values

Multi-line text fields can include plain or rich text. If a field is edited as plain text, all formatting is removed. Inline images are preserved, but they are appended to the end of the field. You can use the formattedTextSupport function to control how a multi-line text field is edited.

For example, a defect's Workaround field contains the following formatted text:

Some text here

The text is stored in TestTrack 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

Editing inline images

Multi-line text fields can contain inline images. The attachment record must exist and must be referenced by the multi-line text field value.

For example, a defect's Workaround field contains the following text and image:

Some text and an image

The text and image is stored in TestTrack as:

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

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

The following example shows how to upload an image to a defect'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 file name 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 defect is added with the inline attachment in the Workaround field
svr.addDefect(cookie, dft);

Note: File data for inline images stored in the m_pFileData member of the CFileAttachment object must be encoded. See Encoding Inline Image and Attachment File Data in the TestTrack SDK.

When retrieving the defect, the Workaround field value will be 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); 

Article ID: 481  |   Last updated: 23 Dec, 2014
Tags
SDK SOAP multi-line text field inline image

Prev   Next
TestTrack SDK     Invalid Type and Missing Tag Value Errors in SOAP Applications...