adamecr / Common.DMN.Engine

DMN Engine is a decision engine (rule engine) allowing to execute and evaluate the decisions defined in a DMN model. Its primary target is to evaluate the decision tables that transform the inputs into the output(s) using the decision rules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DmnExecutionContext.ExecuteDecision() seems to be using the label instead of the name to identify output from a dependent Decision

ongbt opened this issue · comments

commented

I am using the downloaded DMN (v1.3) from https://consulting.camunda.com/dmn-simulator/

I changed the Inputs' name to 'season', 'guestCount', 'guestsWithChildren' from the original 'Season', 'Number of Guests', 'Guests with children?' so that WithInputParameter will run correctly.

        string fileName = "simulation.dmn";
        var def = DmnParser.Parse(fileName, DmnParser.DmnVersionEnum.V1_3);
        var ctx = DmnExecutionContextFactory.CreateExecutionContext(def);
        ctx.WithInputParameter("season", "Winter");
        ctx.WithInputParameter("guestCount", 1);
        ctx.WithInputParameter("guestsWithChildren", true); 
        var outcome = ctx.ExecuteDecision("Beverages");

        foreach (var result in outcome.Results)
        {
            foreach (var variable in result.Variables)
            {
                Console.WriteLine(variable.Name + ": " + variable.Value);
            }
        }

At the line 'var outcome = ctx.ExecuteDecision("Beverages");', I encountered this exception:
DynamicExpresso.Exceptions.UnknownIdentifierException: 'Unknown identifier 'desiredDish' (at index 0).'

I looked at the DMN file and saw that the Beverages decision has an input:

<inputExpression id="LiteralExpression_0bqgrlg" typeRef="string"> <text>desiredDish</text> </inputExpression>
... that is the output from Dish decision:
<output id="OutputClause_0lfar1z" label="Dish" name="desiredDish" typeRef="string" />

When I changed the output clause of Dish decision to the following, the code worked:
<output id="OutputClause_0lfar1z" label="desiredDish" name="desiredDish" typeRef="string" />

Seems like you are using the label as the identifier of the output element instead of using name.

Hello @ongbengtiong,
your last statement "Seems like you are using the label as the identifier of the output element instead of using name." is correct. It's also mentioned in the Outputs in XML chapter of documentation.

The reason why I decided to do it this way is that label is something that is what you seen in the Camunda decision table designer (and in the simulator as well) by default. Also when you create an output, the output name is empty by default and I think the most of users just set the label.

So the behavior you described is "as designed". Frankly I'm not sure whether to change (update) the design to take the name into the consideration as well, because this will probably be breaking change and a lot of existing DMN files might stop working properly, so there will have to be some king of flag/policy allowing the user to override the current behavior when needed.

Thanks
Radek

closing the ticket, works as designed