Oh my, aren't we a wee bit too dogmatic? I've certainly been known as being a stickler to style and best practice and what not, but in this particular case I'd use a single rule and offload the earth-shaking decision between 'Y' and 'N' into a function:

rule x
when
   samplefact1( $status: status, state == "CA" )
then
   fact0.setField1(  yn( $status)  );
end

Cheers
-W


On 26 January 2012 18:25, Welsh, Armand <AWelsh@statestreet.com> wrote:
You cannot, under normal circumstances, place conditional login in the RHS.  This is by design.  Any conditional logic belongs in the LHS.  If you need to perform conditional logic in the RHS, this is usually an indicator that they rule is not written correctly.

Now, with that said, there are times when you specifically want to put a decision component in the RHS.  I would do this using a function.

In your case, it really would make sense to use two rules, to represent your one case, like this:


Rule 1
when
               samplefact1( status == "active", state == "CA" )

then
               Response fact0= new Response();
               fact0.setField1( "Y" );
               fact0.setName( "something " );

               insert(fact0 );
end

Rule 2
when
               samplefact1( status != "active", state == "CA" )

then
               Response fact0= new Response();
               fact0.setField1( "N" );
               fact0.setName( "something " );

               insert(fact0 );
end


These two rules are mutually exclusive, only one will fire, and you get the result you want.  It's really about changing the way you think about decision factors.  You can also achieve the same result like this:


Rule 1
when
               samplefact1(state == "CA" )

then
               Response fact0= new Response();
               fact0.setName( "something " );

               insert(fact0 );
end


Rule 2a
when
               samplefact1( status == "active", state == "CA" )
               $resp : Response ( field1 != "Y")

Then
       modify( $resp ) { setField1( "Y" )  };end

Rule 2b
when
               samplefact1( status != "active", state == "CA" )
               $resp : Response ( field1 == "Y")
then
       modify( $resp ) { setField1( "N" )  };
end

In this scenario, you are changing from hard data mapping to an event oriented rule.  Rule1 creates the basic Response fact, and Rules 2a&2b enrich the response fact based on conditions that may arise throughout the processing of the rules, independent of the initial creation step.  Just whenever you have a response fact that is not Y, set it to Y, and of course the inverse rule...  This requires more processing for the rules, but in a large rules based system this may be more in-line with what  you really want.

Armand

-----Original Message-----
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of vadlam
Sent: Thursday, January 26, 2012 8:11 AM
To: rules-users@lists.jboss.org
Subject: [rules-users] setting different value in consequence ( RHS part) based on a conditional check

Hi,

we have an existing BRL rule in Guvnor whereby we set the value of some
fields in RHS based on some value checks in the condition part. we have
created several of these rules already in a previous release.

In the next release, we have new requirements to set the value of an
existing field  in consequence to be of 2 different values based on a
specific conditional evaluation. the rest of the rule remains the same.

to clarify,

when
               samplefact1( status== "active" , state=="CA" )

           then

               Response fact0= new Response();
               fact0.setField1( "Y" );
               fact0.setName( "something " );

               insert(fact0 );
       end

we now have to change this to set Field1 value to Y or N based on some
updated condition for status field.

 lets say if status=="active" , Field1 has to be Y, but when status=closed,
then Field1 has to be N

Please keep in mind that the rest of the rule remains the same.

is there a way to set the value of Field1 to be Y or N within the
consequence part of same rule without having to create another rule .

will the use of functions or variables be of any help in this case?







--
View this message in context: http://drools.46999.n3.nabble.com/setting-different-value-in-consequence-RHS-part-based-on-a-conditional-check-tp3690826p3690826.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users