Answered

How can I count the records in an unrelated entity that match certain criteria

How can I count the records in an unrelated entity (Meters table) that match certain criteria. Then compare the count with another fixed number. If count is greater than the fixed number it must throw a validation error. I have been playing around all day, but not working. What am I doing wrong? I dont need to create a new collection or array of values, just check the count. Thank you.

var Manuf = <ProcessEntity.SingleMeter.Manufacturer>;

var NumMeters = 10;

SelectedMeters = Me.getXPath("entity-list('Meters','Maunfacturer

== Manuf')");

//I ALSO TRIED THE FOLLOWING:

// SelectedMeters =

CEntityManager.GetEntity("Meters").GetEntityList("Manufacturer","Manufacturer

= Manuf","","");

// for(Counter=0; Counter < SelectedMeters.Length; Counter++)

// NumMeters =

SelectedMeters.Length

if(<count(SelectedMeters)> > NumMeters)

{

CHelper.ThrowValidationError("A Manufacturer cannot have more than 10 meters");

}

Comments (7)

photo
1

Dear Jane,

Please try the following code:

  1. var Manuf = <ProcessEntity.SingleMeter.Manufacturer>;
  2. var NumMeters = 10;
  3. SelectedMeters = CEntityManager.GetEntity("Meters").GetEntityList("Manufacturer","Manufacturer="+Manuf,"","");
  4. if(SelectedMeters.Length > NumMeters)
  5. {
  6. CHelper.ThrowValidationError("A Manufacturer cannot have more than 10 meters");
  7. }

We recommend to follow your expression through some traces. For further information: http://help.bizagi.com/bpm-suite/en/index.html?validating_my_business_r.htm

We look forward to hearing from you

photo
1

Great I tried again yesterday and had almost the same as the above, but just couldn't get the filter to work unless I just typed in a value. I had tried "Manuf", "Manufacturer = Manuf", and even "Manufacturer = +Manuf+". I will try this today and let you know.

Sorry but It did not work. The expression works fine if I manually enter "Manufacturer","IBM","","") but as soon as I try "Manufacturer","Manufacturer="+Manuf,"","") there are no values in SelectedMeters and count is 0.

photo
1

Dear Jane,

We would like to know if you were able to implement the filter correctly. You may implement this function: Me.getXPath("entity-list('Entity','Filter')"); instead of: CEntityManager.GetEntity("Meters").GetEntityList("Manufacturer","Manufacturer="+Manuf,"","");

This article from our help site can help you to resolve it:

http://help.bizagi.com/bpm-suite/en/index.html?access_entities_not_related_to.htm

We look forward to hearing from you

photo
1

Ok I changed it to getXPath. Here is the full expression but I don't think I have the correct syntax for the entity-list for SelMeters?

var Manuf = <ManageMeters.SingleMeter.Manufacturer>;

CHelper.trace("MeterCountChecks","Manuf=

"+Manuf);

//SelMeters =

CEntityManager.GetEntity("Meters").GetEntityList("Manufacturer","Manufacturer="+Manuf,"","");

SelMeters = Me.getXPath("entity-list('Manufacturer','"Manufacturer= "+Manuf')");

CHelper.trace("MeterCountChecks","SelMeters=

"+SelMeters);

CountMeters = SelMeters.Length;

CHelper.trace("MeterCountChecks","CountMeters=

"+CountMeters);

if (CountMeters > 10)

{

CHelper.ThrowValidationError("An

Electrician cannot have more than 10 meters issued to them");

}

photo
1

Sorry I sorted out the entity name, but must be missing something still?

I tried ('Meters','"+Manuf+"') and then tried

SelMeters = Me.getXPath("entity-list('Meters','"Manufacturer= "+Manuf')");

CHelper.trace("MeterCountChecks","SelMeters= "+SelMeters);

CountMeters = SelMeters.Length;

photo
1

I also tried manually typing in a value for the filter but nothing was found:

SelMeters = Me.getXPath("entity-list('Meters','Meters.Manufacturer= \"IBM\"')");

any feedback would be most gratefully received.

photo
1

OK I got the first option to work by removing all the quotes from the filter variable - does that seem correct !?

SelMeters = CEntityManager.GetEntity("Meters").GetEntityList("Manufacturer",Manuf,"","");

I am struggling with the second option though?

SelMeters = Me.getXPath("entity-list('Meters', "Manufacturer ="+Manuf')");

Does not work.