I looked into the documentation, but it's not clear how to retrieve an instance using a guid as an input.
Next I'd also like to retrieve a field value from that instance object.
I already have a DomHelper object. So far so good.
Any ideas on how to go about the rest?
Hi Jeroen,
Let me quickly give you few pseudo code snippets (C# blocks):
GET DOM INSTANCE
// Retrieve the DomInstance var helper = new DomHelper(engine.SendSLNetMessages, "MODULE ID"); var filter = DomInstanceExposers.Id.Equal(<DOM INSTANCE ID>); var domInstance = helper.DomInstances.Read(filter).FirstOrDefault();
GET FIELD OF DOM INSTANCE (follow up on code block above)
var instanceField = domInstance.Sections?.FirstOrDefault().GetFieldValueById(< DOM DESCRIPTOR ID >); object instanceValue = instanceField?.Value.Value;
Note: I assume it is better to for-loop the sections list.
Documentation: Altering values of a DomInstance - examples | DataMiner Docs
Hope this helps you further
Hi Jeroen,
You can find some sample code below.
Note that I've hard-coded the section definition id and field descriptor id.
Ideally you store the ids in a separate class to make the code more readable.
public void Run(IEngine engine)
{
try
{
Guid domInstanceId = new Guid(engine.GetScriptParam("Dom Instance ID").Value);DomInstance domInstance = GetDomInstance(engine, domInstanceId);
string myValue = GetSectionField<string>(domInstance, new SectionDefinitionID(new Guid("7a1fb82e-44be-4c27-a7ab-60b83417bf7a")), new FieldDescriptorID(new Guid("5506da8b-9af0-43df-9c81-4a0bb2bed851")));
engine.GenerateInformation($"Value: {myValue}");}
catch (Exception ex)
{
engine.GenerateInformation($"Error: {ex}");
engine.ExitFail(ex.ToString());
}
}public static DomInstance GetDomInstance(IEngine engine, Guid domInstanceId)
{
var domHelper = new DomHelper(engine.SendSLNetMessages, "lab_hq");FilterElement<DomInstance> domFilter = DomInstanceExposers.Id.Equal(domInstanceId);
return domHelper.DomInstances.Read(domFilter).SingleOrDefault();
}public static T GetSectionField<T>(DomInstance domInstance, SectionDefinitionID sectionDefinitionId, FieldDescriptorID fieldDescriptorId)
{
var section = domInstance.Sections.SingleOrDefault(x => x.SectionDefinitionID.Id == sectionDefinitionId.Id);if (section == null)
{
return default(T);
}var flowsField = section.FieldValues.SingleOrDefault(x => x.FieldDescriptorID.Id == fieldDescriptorId.Id);
if (flowsField == null)
{
return default(T);
}return (T)flowsField.Value.Value;
}