Updating an attribute of all BOs - strange behavior

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
ckirnbauer
Posts: 68
Joined: Wed Oct 04, 2006 2:46 pm

Updating an attribute of all BOs - strange behavior

Post by ckirnbauer »

Hello,

I have a bo Contract, that owns multiple objects Member, moreover the identifier Contract.TContractID is stored with every child-object Member, exactly in Member.TContractID.

In Member, there exists Yes/No flag IsMainMember, that can be only for one child-object YES the others must be NO

I added Member-rule:
IF Member.IsMainMember = 'Yes' Then MembersIsMainMember

MembersIsMainMember process looks like following:
###################
input: Bo Member

rule1) FIND ALL Member
rule2)
If Member.TContractID=ThisMember.TContractID AND Member.MemberID<>ThisMember.MemberID Then
Member.IsMainMember='No'
################################

In other words, I search for all Members in this Contract except this-Member and set flag to NO.

THE PROBLEM
=========
When there are 2 Member Objects, the mechanism works fine.
But when there are 3 Member Objects or more, there is a bug. It happens, that 2 Member Objects have the flag set to YES, what is very WRONG.

The log viewer says, that e.g. memberid16 and memberid17 were evaluated to true and 2 actions were added to agenda.
Member16 is being executed and changed to NO correctly
Member17 is being executed but "values wasn't changed.." AND there is the big PROBLEM, Member17 should also be changed.

Please tell me, if this is a bug and how I can implement the issue correctly.

Kind regards
Chris
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Hi Chris,

This is not a bug. You need to change your process to look like this:

Rule 1: FIND Member WHERE Member.TContractID=ThisMember.TContractID AND Member.MemberID<>ThisMember.MemberID
Rule 2: Member.IsMainMember='No'
Aware IM Support Team
ckirnbauer
Posts: 68
Joined: Wed Oct 04, 2006 2:46 pm

Post by ckirnbauer »

Hi!

DONE ACTIONS
======

So I changed Process IsMainMember to following:
###########
Rule 1: FIND Member WHERE Member.TContractID=ThisMember.TContractID AND Member.MemberID<>ThisMember.MemberID
Rule 2: Member.IsMainMember='No'
##########

In Member object, I have the rule HandleMainMember:
#####
If Member WAS CHANGED AND Member.IsMainMember='Yes' Then
MemberIsMainMember
##


PROBLEM
======

But now, when I set IsMainMember='Yes' and click onto SAVE, the own object where checkbox was activated switches to IsMainMember='No' after saving (WHAT IS VERY WRONG)

The log says (I have 5 members):
rule found 4 objects
then there are 4 statements to set IsMainMember='No' (WHAT Is OK)
But there is a fifth statement, that also sets IsMainMember='No' (WHAT I DO NOT UNDERSTAND AND WHAT IS WRONG).

BASIC QUESTION
============

So, the basic question is:
how does RULE 1 with the FIND-command know, that the statement
Rule2: Member.IsMainMember='No' belongs to the found objects one statement before????

So, what did I do wrong?
Kind regards
Chris
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Hi Chris,

This happens because the original Member object is passed to the process as process input. Therefore it is placed in the context of the process with the other Member objects found by the query and the action is then executed for all objects in the context.

To avoid this you need to use an object of different type as the process input. For example, if the Contract has a reference attribute to its main member, you can change your rule on Member as follows:

IF Member.IsMainMember = 'Yes' Then
Member.Contract.MainMember = Member
MembersIsMainMember USING Member.Contract

The MembersIsMainMember process should now take Contract as its input and look like this:

Rule 1: FIND Member WHERE Member.TContractID = Contract.TContractID AND Member <> Contract.MainMember
Rule 2: Member.IsMainMember='No'


A more efficient version of this implementation would be to remove the process and get the Contract object to do its work. Then your rule on Member would look like this:

IF Member.IsMainMember = 'Yes' Then Member.Contract.MainMember = Member

and you would need to add the following rule to Contract:

If Contract.MainMember WAS CHANGED Then
FIND Member WHERE Member.TContractID = Contract.TContractID AND Member <> Contract.MainMember
Member.IsMainMember='No'
Aware IM Support Team
Post Reply