"
This article describes how to add dynamic attributes to an entity. It allows business users to define characteristics for entities like products, without having to go through development.
The example detailed in this article is using the model from the Product Retail demo application as a starting point and is adding dynamic attributes to define specific attributes per product, depending on the product subfamily.
Pre-requisite: if no retail model is available, you must follow the entire Product Retail tutorial first to initialize the product model.
Step by step guide
1. Create 4 entities ( ProductAttribute, AttributeValue, AttributeSubFamily, Attribute) with their relationships, as shown on the diagram below.
- Attribute: All attributes created for product subfamilies.
- AttributeValue: For constrained attributes, values are stored in this table.
- AttributeSubFamily: Associate the attributes to the subfamilies products
- ProductAttribute: Associate the attributes to the products.
2. Create the application components for the new entities and deploy the model changes.
3. Connect to the application and populate the Attributes table with all the needed attributes.
4. Add values for the attributes using a list of values:
5. Associate the Attributes to their Subfamilies:
6. [Optional]Automatically link Attributes with Products
This step is optional. It allows to automatically retrieve the Attributes according to the each Product Subfamily for a given load ID, and associate them with this Product. Alternatively, it is possible to add the Attributes manually on each Product.
a. To automatically associate the attributes to the product being created, you first need to declare a PL/pgSQL procedure.
PL/pgSQL function to associate the Attributes to Products by Subfamily.
create or replace function usr_create_productattributes(p_loadid numeric) returns void
language plpgsql
as $function$
begin
insert into sa_product_attribute (
b_loadid, b_classname, b_creator, b_credate, product_attribute_id, f_product, f_attribute
)
select sp.b_loadid, 'ProductAttribute', sp.b_creator, sp.b_credate, nextval('seq_product_attribute'), sp.id, gsf.f_attribute
from sa_product sp
inner join gd_attribute_sub_family gsf on sp.f_sub_family = gsf.f_sub_family
where b_loadid = p_loadid
and not exists (
select 1 from sa_product_attribute sa
where sa.f_product = sp.id and sa.f_attribute = gsf.f_attribute
);
end;
$function$;
b. Next, set the step triggers with the created PL/SQL on the Product’s stepper:
8. You can see the Attributes associated with the Product as below and set their value :
9. Additional Attributes can be shown on the Product card by adding the Product Attribute's collection on the product's form view: