1 Reply Latest reply: Dec 17, 2012 5:05 PM by Ben Rogers RSS

    How to compare attributes in different entities?


      I would like to compare/verify that a number of attributes in an entity is identical to another set of attributes in another entity. The type of attribute is text.
      How is the best way of doing this?


        • 1. Re: How to compare attributes in different entities?
          Ben Rogers
          Hi Robert,

          The simplest way is to use the ExistsScope function.
          So for example, imagine two entity sets, "the employee" and "the personnel record" (there can be many instances of employees and many instances personnel records). Assume that both of these entities are contained by global (i.e. they have no direct relationship to each other).

          Im not sure why you want to compare the two, so here are a few examples of things you can do, and you can apply whichever is most relevant to you.

          Firstly, you can write a boolean that basically confirms if an employee has a record:

          the employee has a personnel record if:
          ..ExistsScope(the personnel records)
          ....the employee's name = the personnel record name
          ....the employee's home office = the personnel record office

          This is just a simple Boolean that will confirm that there is at least one personnel record instance that matches the employee's name & home office. If that is all you need to do then it's by far the simplest way to achieve it in OPA. Here is a useful article which goes into more detail: http://docs.oracle.com/html/E27987_01/Content/Reference/Rule%20function%20examples/Entity_and_relationship_functions.htm

          Often, however, it is useful to "match" one entity instance with another, and then run rules on the "matched instance"...
          For example, once the employee's personnel record has been identified, it may be useful to run some more detailed rules. You could create an inferred relationship between the employee and the personnel record, and call it "the employee's personnel record".

          For example:

          the personnel record is a member of the employee's personnel record if:
          ..the employee's name = the personnel record name
          ..the employee's home office = the personnel record office

          Then once you have this relationship, you can then use it in later rules:

          the employee should be promoted if
          ..ForScope(the employee's personnel record)
          ....the personnel record's assessment score > 80

          This is particularly useful if you have a large number of instances. The comparison will only be done once to create the inferred relationship and not each time you want to reason about "the employee's personnel record".

          More about inferred relationships here:

          I hope this helps, post back if you have any more questions.