Skip to Content
0

Nodes and AlternativeKeys

Apr 26, 2017 at 12:40 PM

74

avatar image

Hi,

a pretty (apparently) newbie problem I just stumbled over:

Say I want to assign a number of Opportunities to a Sales Quote (could be any other business object).

Most basic approach: I create a new node, say RelatedOpportunities [0,n], inside the Quote XBO and define a new field OpportunityID as AlternativeKey - as I do not want the same Opportunity to be assigned more than once to the same quote.

[Extension] businessobject AP.CRM.Global:CustomerQuote {
	node RelatedOpportunities [0,n]
	{
		[AlternativeKey] element Opportunity_ID : BusinessTransactionDocumentID;
	}
}

With this setup, something funny is happens:

Say I'm adding opportunity A to Quote 1. No problem. Try to add opportunity A to Quote 1 again => error message: Instance with the same key (A) already exists. So far no problem.

Now, try to add opportunity A to Quote 2. Expected behavior: No problem. Actual behavior: error message "Instance with the same key (A) already exists)".

Why is that? I would expect the Quote ID from the root node to be the (invisible) first key here. But the way the system actually behaves is as though the RelatedOpportunities node were an individual business object (which I would expect to only allow one Key entry globally).

And what's the suggested work-around? Do I really need to add another AlternativeKey for the Quote ID? This would be counter-intuitive - that ID is already present at the root node. Also, the manual says "It is not possible to have more than one alternative key of the same type in a business object node." But both would be of type BusinessTransactionDocumentID.

Thanks for your help

Stefan

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Fred K Apr 27, 2017 at 03:03 AM
0

Hi Stefan,

As far as I know, nodes are treated as separate tables in back end. (just my assumption because we cannot see how they are implemented)

That's why the alternative key in a node behaves globally unique regardless of the parent node instance.

Child node instances and parent node instances are somehow linked with a hidden foreign key. (also assumption)

What we normally do for this kind of situation is we create a compound alternative key and that key will hold the combination of Parent Node ID and the child node ID.

We implements this in BeforeSaveEvent script.

compoundKey = parentNodeID + childNodeID;

※There might be some other way though.

Best Regards,

Fred

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hello Stefan,

Fred is complete correct.

Every AlternativeKey MUST be unique over all instances of this node, regardless if it is a Root node or any sub-node.

As Fred suggest: Define your AltKey as a concatenation of Quote-Opportunity.

Bye,
. Horst

0