In this section of the manual, we’ll explore some useful tips and tricks for managing grids using business rules.

  1. How To Add a New Row in a Grid Linked to a Mid-Entity (Many-to-Many) When the Item Does Not Already Exist

To learn how to add a new row in a grid linked to a mid-entity (or mid-table) when the item does not already exist, refer to the following set of instructions:

  • Create the two entities that you want to link together (e.g. Product and Supplier)
    • For each entity, create the relevant set of attributes.
  • Create a mid-entity with the two foreign keys (e.g. Product_Supplier)
  • Create a form associated with the mid-entity
    • Inside the form, add all required controls for the attributes of the child entity (e.g. all attributes of Supplier)
  • Create a pre-form action for the form.
    • In the code, create a new domain object for the referenced child entity.
      • Code Example
        if (domainObject.BPMAPP_BCM_Action_ItemFK_ActionItem  null)
        {
          	var actionItem = (Ray.BPMApp.BCM.Model.BPMAPP_BCM_Action_Item)(bpmAppService.UnitOfWork.CreateDomainObject(typeof(Ray.BPMApp.BCM.Model.BPMAPP_BCM_Action_Item)));
           	domainObject.BPMAPP_BCM_Action_ItemFK_ActionItem = actionItem;
           	if (actionItem.BPMAPP_BCM_BCP_ActionItem_Execute_MidsFK_ActionItem  null)
           	{
           		actionItem.BPMAPP_BCM_BCP_ActionItem_Execute_MidsFK_ActionItem = new List<Ray.BPMApp.BCM.Model.BPMAPP_BCM_BCP_ActionItem_Execute_Mid>();
           	}
           	actionItem.BPMAPP_BCM_BCP_ActionItem_Execute_MidsFK_ActionItem.Add(domainObject);
        }
  • Configure the governance properties of the grid control (to which the mid-entity is linked).
    • Enable the control’s ‘new’ functionality and set up the corresponding form behavior (‘New Form’).
      • This will allow users to open the previously created form directly from the grid.
  1. How To Prevent Duplicates in a Grid

To learn how to prevent duplicate entries in a grid, consider the following example:

  • In the database, there are two custom entities, Product and Supplier, which have their own corresponding set of attributes.
    • These two entities are linked together by a mid-entity through foreign keys.
  • In the Supplier form, there is a grid linked to the mid-entity, which displays the mid-objects, i.e., the supplier’s products.
    • Using the grid, users can add products to the supplier, but each product should only be added once.
      • To achieve this, users must write code to implement the necessary logic.
        • Code Example
          if(domainObject.BPMAPP_Mid_Supplier_ProductsSupplier != null)
          {
          	var productIds = new List();
          	var midsToDelete = new List(); 
          	foreach(var mid in domainObject.BPMAPP_Mid_Supplier_ProductsSupplier)
          	{
          		if(productIds.Contains(mid.BPMAPP_ProductProduct.Id))
          			midsToDelete.Add(mid);
          		else
          			productIds.Add(mid.BPMAPP_ProductProduct.Id);
          	}
          	foreach(var mid in midsToDelete)
          	{
          		bpmAppService.BPMSServices.DomainObjectService.DeleteDomainObject(mid);
          	}
          	domainObject.BPMAPP_Mid_Supplier_ProductsSupplier = domainObject.BPMAPP_Mid_Supplier_ProductsSupplier.Where(m => !midsToDelete.Contains(m)).ToList();
          }