Completed
Last Updated: 12 Apr 2022 14:57 by ADMIN
Release R2 2022
Kalle
Created on: 18 Mar 2022 08:49
Category: WordsProcessing
Type: Bug Report
0
WordsProcessing: Calling MailMerge method for an If field with no defined FalseText throws System.NullReferenceException

When calling the MailMerge method on a RadFlowDocument, which includes an IF field, where no FalseText (value to display when the expression evaluates to FALSE) is defined the following exception is thrown System.NullReferenceException: 'Object reference not set to an instance of an object.'

Workaround: Setting a string (empty works too) for the FalseText. 
When the document is passed to the following method, all IF fields are edited so that the exception is not thrown:

private void EmptyIfSecondArgumentWorkaround(RadFlowDocument document)
{
	List<FieldCharacter> collection = document.EnumerateChildrenOfType<FieldCharacter>().Where(f => f.FieldCharacterType == FieldCharacterType.Start).ToList();

	for (int i = 0; i < collection.Count; i++)
	{
		FieldInfo item = collection[i].FieldInfo;
		string code = item.GetCode();
		FieldCharacter separator = item.Separator;
		FieldCharacter end = item.End;

		if (code.TrimStart().StartsWith("IF"))
		{
			FieldCharacter codeEnd;
			if (separator.Paragraph != null)
			{
				codeEnd = separator;
			}
			else
			{
				codeEnd = end;
			}
			string emptyString = " \"\" ";
			string mergeFormatCodeSuffix = "\\*";
			if (codeEnd.Paragraph.Inlines.Count > 1)
			{

				string editedMergeFormatCodeSuffix = string.Join("", new string[] { emptyString, mergeFormatCodeSuffix });
				int codeEndIndex = codeEnd.Paragraph.Inlines.IndexOf(codeEnd);
				Run run = codeEnd.Paragraph.Inlines[codeEndIndex - 1] as Run;
				if (run.Text.Contains(mergeFormatCodeSuffix))
				{
					run.Text=run.Text.Replace(mergeFormatCodeSuffix, editedMergeFormatCodeSuffix);
				}
				else
				{
					run.Text += emptyString;
				}
			}
		}
	}
}

1 comment
ADMIN
Peshito
Posted on: 12 Apr 2022 14:57

Hello,

This item will be available in R2 2022 Release. 

It is also available with Telerik UI for WPF's latest internal build - LIB 2022.1.418 (18 Apr 2022) if you need it earlier.

Regards,
Peshito
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.