--- alias: tutorials-name-generator-integration timetoread: true hide: - toc description: "This documentation outlines integrating a new material creation process within CM MES" --- # Integration 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: ```Json { "Cookie": { "Facility": "Cookie Factory", "Flow": "CookiesFlow", "Step": "Mixing", "Product": { "Name": "Belgas", "Version": "1", "Revision": "A" }, "Quantity": 3 } } ``` Along with the [[integrationhandlerresolution-st]] Smart Table configuration: ![Screenshot showing a mathematical equation with variables 'a' and 'oe', possibly related to an integration process.](../images/integration_01.png) As well as the **DEE Action** code below: ```C# var serviceProvider = (IServiceProvider)Input["ServiceProvider"]; IEntityFactory entityFactory = serviceProvider.GetService(); IMaterialOrchestration materialOrchestration = serviceProvider.GetService(); //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 data = JsonConvert.DeserializeObject>(jsonString); JObject materialInfo = JObject.FromObject(data["Cookie"]); //Obtain all the fields present in the message. string facilityName = materialInfo["Facility"].ToString(); IFacility facility = entityFactory.Create(); facility.Load(facilityName); string flowName = materialInfo["Flow"].ToString(); IFlow flow = entityFactory.Create(); flow.Load(flowName); string stepName = materialInfo["Step"].ToString(); IStep step = entityFactory.Create(); 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(); 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(); 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: ![Screenshot showing a call to the material orchestration API to create an instantiated material.](../images/integration_02.png) !!! note For more information on how to configure the Name Generator for each entity, see [[user-guide-name-generator]]. The following **Material** was created, and its name was automatically generated: ![Screenshot showing a UI with a field labeled "Material" highlighted, as defined in the Name Generator.](../images/integration_03.png) 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.