gorules / zen

Open-source Business Rules Engine for your Rust, NodeJS, Python or Go applications.

Home Page:https://gorules.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It can't work normally when the inputs is an array of object.

Kenscofield opened this issue · comments

Hi, I'm glad to use the amazing tool. But I find that it seems that it can't work normally when the inputs is an array of object. And I don't know if my operating as following is wrong, could you pls give me some advice, thx.

1699263719042

Hi @Kenscofield, thanks for your feedback!

This is one of the things that we are aware of and plan to build upon in future with additional nodes (similar to loop/repeater). The best approach when using array of outputs (COLLECT) in the meantime is through a function. See more information in the following discussion:

#90

Hi @stefan-gorules, thanks for your reply.
The disussion #90 is that the output is an array of obj, but waht I'm asking is the input is an array of obj. Is the way of solving the two cases same?

By the way, if I use the function node as one of the input column of the decision table, is there any difference from filter something without the goRules? I'm looking forword for your reply.
Thx

I see what you mean @Kenscofield, it seems that this issue stems from using https://editor.gorules.io which doesn't have the most recent version. When running it on latest zen-engine I get the following:

isolate.inject_env(&json!({ "activeEvents": [{ "id": 1 }, { "txt": 2 }] })); // this is our ENV
image

We will try to update our https://editor.gorules.io when we get some time.

By the way, if I use the function node as one of the input column of the decision table, is there any difference from filter something without the goRules? I'm looking forword for your reply.
Thx

Regarding your 2nd comment, you can use filter in either your code or within GoRules, it is up to you to decide. Usually this decision depends on what you want to be controlled within Rules Engine, and what you want outside. Performance wise it's better to filter outside of GoRules as JavaScript isolates have a small start-up time.

Below I'm attaching JSON file of how I would achieve what you're describing, and some code for Node.JS on how you can run it (Python and Rust have similar approach). Best place to preview it is on storybook until we update editor. https://gorules.github.io/jdm-editor/?path=/story/decision-graph--controlled

zen-issue-96.json

import { ZenEngine } from '@gorules/zen-engine';
import * as fs from 'fs';

(async () => {
  const engine = new ZenEngine();
  const decisionData = fs.readFileSync('zen-issue-96.json');
  
  const decision = engine.createDecision(decisionData);
  const response = await decision.evaluate({ activeEvents: [{ id: 1 }, { txt: 2 }] });
  console.log(response);
})();

That's so great. I will try it again. And I'm waiting for your team updating on the editor.
Thanks for your patience

hi @stefan-gorules, could you please help check the case. It seems soemthing wrong.
image

Hi @Kenscofield,

Based on what you're trying to achieve, I'd approach it in the following way:
image

Hello @stefan-gorules

This is one of the things that we are aware of and plan to build upon in future with additional nodes (similar to loop/repeater).

Any update on this feature? It would be great enhancement. I was looking for a way to handle an array of objects in the input context but I did not find any, other than doing everything in the JavaScript lambda component.

We are building settlement system and those rules are quite complicated billing rules (pricing). In my use case non-technical people would be using JDM Editor to update the decision table values, so I can't really ask them to edit JavaScript code.

So far the solution we choose is to launch rule evaluation on each item separately from app code (so input is just one object)