Integration#
Estimated time to read: 3 minutes
This scenario represents an integration to create a new Material of form Cookies in CM MES.
The external system provides the following information:
- Facility
- Flow
- Step
- Product
- Primary Quantity
Therefore, CM MES must be able to generate a unique name.
Taking into account this message received in CM MES:
{
"Cookie": {
"Facility": "Cookie Factory",
"Flow": "CookiesFlow",
"Step": "Mixing",
"Product": {
"Name": "Belgas",
"Version": "1",
"Revision": "A"
},
"Quantity": 3
}
}
Along with the IntegrationHandlerResolution Smart Table configuration:
As well as the DEE Action code below:
var serviceProvider = (IServiceProvider)Input["ServiceProvider"];
IEntityFactory entityFactory = serviceProvider.GetService<IEntityFactory>();
IMaterialOrchestration materialOrchestration = serviceProvider.GetService<IMaterialOrchestration>();
//Obtain the Integration Entry created by the external system in CM MES.
IIntegrationEntry integrationEntry = Input["IntegrationEntry"] as Cmf.Foundation.BusinessObjects.IntegrationEntry;
//The message in the Integration Entry in always stored as an byte array.
//Convert the byte array to a dictionary and then to the desired json object.
string jsonString = Encoding.UTF8.GetString(integrationEntry.IntegrationMessage.Message);
Dictionary<string,object> data = JsonConvert.DeserializeObject<Dictionary<string,object>>(jsonString);
JObject materialInfo = JObject.FromObject(data["Cookie"]);
//Obtain all the fields present in the message.
string facilityName = materialInfo["Facility"].ToString();
IFacility facility = entityFactory.Create<IFacility>();
facility.Load(facilityName);
string flowName = materialInfo["Flow"].ToString();
IFlow flow = entityFactory.Create<IFlow>();
flow.Load(flowName);
string stepName = materialInfo["Step"].ToString();
IStep step = entityFactory.Create<IStep>();
step.Load(stepName);
string productName = materialInfo["Product"]["Name"].ToString();
string productVersion = materialInfo["Product"]["Version"].ToString();
string productRevision = materialInfo["Product"]["Revision"].ToString();
IProduct product = entityFactory.Create<IProduct>();
product.Name = productName;
product.Version = int.Parse(productVersion);
product.Revision = productRevision;
product.Load();
int cookiePrimaryQuantity = (int)materialInfo["Quantity"];
//Instantiate the material entity with the necessary properties.
IMaterial material = entityFactory.Create<IMaterial>();
material.Facility = facility;
material.Flow = flow;
material.Step = step;
material.Form = "Cookie"; //Always cookie, since this is a Cookie Integration. This can be configured. example: using a configuration entry.
material.Product = product;
material.PrimaryQuantity = cookiePrimaryQuantity;
material.Type = "Cookie"; //Always cookie, since this is a Cookie Integration. This can be configured. example: using a configuration entry.
//Call the material orchestration to create the instantiated material.
CreateMaterialInput input = new CreateMaterialInput();
input.Material = material;
materialOrchestration.CreateMaterial(input);
And taking the Name Generator (MaterialNameGenerator) that is used by default in the DEE Action for the CreateMaterial operation:
Note
For more information on how to configure the Name Generator for each entity, see Name Generators.
The following Material was created, and its name was automatically generated:
Looking closely at the name of the Material, the following can be observed:
- Material - the first token defined in the Name Generator as a Constant with the value
Material. - 202510 - the value originating from the second token defined in the Name Generator. The creation date was 14-10-2025, and applying the defined format (yyyyMM), the final value is
202510. - 00002 - the counter defined in the third token of the Name Generator. This means that this is the second Material that was created during the month of October.


