LayoutCollector GetEntity ignoring mergefields inside other fields (IF)

Hi,

According to your documentation, LayoutCollector->GetEnity is not able to return any information regarding position in the document for Runs. However, it seems like the behaviour of LayoutCollector is to ignore any other sibling nodes within a given parent node once a Run is encountered.
I have the following situation

{IF {MERGEFIELD A1} = “SomeValue” “{MERGEFIELD A2}” “[SomeBookmark]”}

This breaks down into the following nodes

FieldStart:
Run: IF
FieldStart:
Run: MERGEFIELD A1
FieldSeparator:
Run: «A1»
FieldEnd:
Run: = "SomeValue
Run: " "
FieldStart:
Run: MERGEFIELD A2
FieldSeparator:
FieldEnd:
Run: " "
Run: SomeBookmark
Run: "
FieldSeparator:
Run: BOOKMARK4
FieldEnd:

The first GetEntity returns the correct position for the first FieldStart, but any other node after the first Run simply returns null.

eg. code:

var doc = new Document(@"D:\LeTest.docx");

var layoutCollector = new LayoutCollector(doc);

var ifStart = doc.Sections[0].Range.Fields[0];

var positions = ifStart.Start.ParentNode.ChildNodes.ToArray().Select(x => new { Node = x, PositionObj = layoutCollector.GetEntity(x) });LeTest.zip (9.9 KB)

@acturisaspose

The LayoutCollector.GetEntity method returns an opaque position of the LayoutEnumerator which corresponds to the specified node. The Alt+F9 in Microsoft Word is used to toggle display of field codes on or off. You are trying to get the position of field that is inside IF field and is not visible in MS Word.

Could you please share some detail about your use case why you need to position of field inside the IF field? We will then provide you more information about your query.