cancel
Showing results for 
Search instead for 
Did you mean: 

Nodes and AlternativeKeys

former_member249896
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member200567
Active Contributor
0 Kudos

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

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

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