Hi,
I'm trying to get information of an DOM instance from an automation script. I'll trigger that script through an low code app and pass the guid of the instance i need to open in the automation script.
Looking at the examples on https://docs.dataminer.services/user-guide/Advanced_Modules/DOM/DOM_examples/DOM_status_system_example.html
there mainly focused on creating and updating fields, but little to no information about reading the information based on having an valid instance guid.
Hi Gerwin,
Below some code examples in case the script is executed from a DOM button in a Low code app.
Load basics
var instanceId = context.ContextId as DomInstanceId;
var domHelper = new DomHelper(engine.SendSLNetMessages, instanceId.ModuleId);
DomInstance domInstance = GetDomInstance(domHelper, instanceId);private static DomInstance GetDomInstance(DomHelper domHelper, DomInstanceId instanceId)
{
FilterElement<DomInstance> domInstanceFilter = DomInstanceExposers.Id.Equal(instanceId);List<DomInstance> domInstances = domHelper.DomInstances.Read(domInstanceFilter);
domHelper.StitchDomInstances(domInstances);return domInstances.First();
}
Go through Sections > FieldValues and store the data in an object
foreach (var section in domInstance.Sections)
{
foreach (var fieldValue in section.FieldValues)
{
var fieldDescriptor = fieldValue.GetFieldDescriptor();
switch (fieldDescriptor.Name)
{
case "Field Descriptor Name":
data.Name = Convert.ToString(fieldValue.Value.Value);
break;default:
break;
}
}
}
Hi Gerwin
Retrieving FieldValues from a DOM instance can be done using the following steps:
- Create an object of the DomHelper class (DomHelper class | DataMiner Docs)
- Create a filter to find the right DOM instance in the collection of instances
Skyline.DataMiner.Net.Messages.SLDataGateway. ManagedFilter<T, F> domInstanceIdFilter = DomInstanceExposers.Id.Equal(domInstanceId);
DomInstance domInstance = domHelper.DomInstances.Read(domInstanceIdFilter).FirstOrDefault(); - Go through all linked Sections
- Use the Skyline.DataMiner.Net.Sections.Section.GetFieldValueById(FieldDescriptorID) method to find the FieldValue (Method GetFieldValueById | DataMiner Docs)
Hopefully this will help you out. Note that there's a change a more efficient way to do this does exist. In case you know a more performant way, please correct my answer.
Kind regards
Took some fiddeling but it does work 🙂 thanks!