I’ve just been writing what should be a really simple function in my DRL.
What I wanted to do is to take an object in, construct another object from it and then insert both into working memory.
Eg.
function
void insertBoth(Object1 object1) {
insert(new Object2(object1));
insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This didn’t work as expected however as it couldn’t find the method insert.
I then thought, ah maybe I need to use the kcontext global to access them
function
void insertBoth(Object1 object1) {
kcontext.insert(new Object2(object1));
kcontext.insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This doesn’t work either so what I’ve had to do is:
function
void insertBoth(KnowledgeContext kcontext, Object1 object1) {
kcontext.getKnowledgeRuntime().insert(new Object2(object1));
kcontext.getKnowledgeRuntime().insert(object 1);
}
Rule XYZ
When
Then
insertBoth(kcontext, new Object1());
End
This is suddenly a lot more complicated than it needs to be. Why can’t functions have the same access to the standard operations (insert, update, retract etc) and globals as rule actions currently do?
Should I raise an issue for this or am I missing something?
Thomas