Hello Dojo community,
I have a requirement to edit (CRUD) instances of exiting Dataminer Object Model programmatically from within a custom API automation script.
I found the following references:
https://docs.dataminer.services/develop/api/types/Skyline.DataMiner.Utils.DOM.html
https://docs.dataminer.services/develop/api/types/Skyline.DataMiner.Utils.DOM.Builders.html
The way I understand it, to i.e. create a new instance I need to do the following:
DomCache dom = new DomCache(messageHandler, moduleId);
DomHelper helper = dom.Helper;
DomInstanceBuilder domInstanceBuilder = new DomInstanceBuilder();
domInstanceBuilder.WithID(guidId);
DomInstance newDomInstance = domInstanceBuilder.Build();
newDomInstance.SetFieldValue("SectionName", "FieldName", "Initial Value", dom);
DomInstanceCrudHelperComponent instanceCrudHelp = helper.DomInstances;
instanceCrudHelp.Create(newDomInstance);
Questions:
- Is this the correct/optimal way?
- How can GUID for the new instance be auto generated?
- What is the recommended implementation of the MessageHandler method passed via the Func delegate when creating the DomCache object.
Many thanks.
Pawel.
Hi Pawel,
Let me try to answer your questions:
- Your code will probably work, but better would be to construct the whole object before calling the Build() method. The SetFieldValue method can be replaced by the WithFieldValue() method on the builder itself.
- If you don't set a GUID yourself using the SetID() method, a random GUID will be assigned to the DOM instance.
- The MessageHandler delegate defines a way to send and receive SLNet messages for communication from the DMA.
- In an automation script it can be used as follows: new DomCache(engine.SendSLNetMessages, "module").
- In a connector: new DomCache(protocol.SLNet.SendMessages, "module").
Please let me know if there are further questions.
Kind regards,
Tom
You’re welcome! I’m glad I could help.
Hi Pawel,
The answer of Tom will set you on your way using the DOM utils NuGet. This NuGet can be very handy, definitely when you are building a complete solution that relies on DOM.
Do note however that using this NuGet is not a requirement to build the script you need. You can also create or update DOM instances using the core DOM API. You are free to choose whichever seems easiest to you. Here are some references on the core DOM API:
https://docs.dataminer.services/user-guide/Advanced_Modules/DOM/DomHelper_class.html#crud-methods
Hi Thomas,
The links have exactly the information I need. Somehow I had missed it before.
Thank you.
Hi Tom,
Many thanks for the answers.