Skip to Content

Nodes and AlternativeKeys


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


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Apr 27, 2017 at 03:03 AM

    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,


    Add comment
    10|10000 characters needed 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.

      . Horst