0
votes

I'm having this issue with a self-referencing 1:N relationship-
I'm trying to associate entity A (of type new_transaction) with entity B (of the same type).
The association works fine (I've checked in the DB- 'new_relatedTransactionId' column is updated correctly).
however, the name column ('new_relatedTransactionIdName') is set to NULL, causing the form to display an empty text box...
enter image description here

I've tried the following methods, with no success-
1.

var rel = new Relationship(relationshipName) {PrimaryEntityRole = EntityRole.Referenced};
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
relatedEntities.Add(relatedTransaction.ToEntityReference());
crmServiceContext.Associate(new_transaction.EntityLogicalName,sourceTransaction.Id,rel,relatedEntities);

2

sourceTransaction.lv_relatedtransactionid = relatedTransaction.ToEntityReference();
crmServiceContext.UpdateObject(sourceTransaction);

3

crmServiceContext.AddLink(sourceTransaction, new Relationship(relationshipName) { PrimaryEntityRole = EntityRole.Referenced }, relatedTransaction);

I've tried switching EntityRole.Referenced and EntityRole.Referencing, still no luck there.
Anyone encountered a similar issue?

1

1 Answers

1
votes

Option 2 is my preferred method of creating this relationship.

The field 'new_relatedTransactionIdName' is not stored in the database, you are actually looking at a SQL View.

If this field is null it would indicate that the Primary Field for entity-record referenced by the Guid in new_relatedTransactionId is blank.

Every entity has a text field defined as its Primary Field. The value of this field, which does not have to be a required field so it can end up being blank, is what will show in the text box in your image.

You do not define this value specific to the relationship, it is created when the entity-record is created and/or updated and used wherever that entity is involved in a relationship.