[Server] How to create an object with default values in some variables
Posted: 10 Jan 2022, 11:05
I'm working on a server that creates instances of objects dynamically like this:
Each object have N variables, I know the string identifier names of those objects (I'm receiving them also dynamically), my issue is that I need those objects to have default values in some of those variables but I can not find an easy way of doing it.
I've tried using the Write method of the new created object like this:
I'm also trying with the NodeData property of the CreateObjectSettings object but as its an object type I've no idea what are the accepted data structures? (there is no documentation about it). I've tried like this without any luck:
What is the right way of doing this?
Code: Select all
var objectTypeNodeId = new ExpandedNodeId(nId, DefaultNamespaceIndex).ToNodeId(Server.NamespaceUris);
var jhObjectId = new NodeId(jhBuilderModel.ObjectName, DefaultNamespaceIndex);
var settings = new CreateObjectSettings
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = jhObjectId,
BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
DisplayName = "a name",
TypeDefinitionId = objectTypeNodeId
};
CreateObject(Server.DefaultRequestContext, settings);
I've tried using the Write method of the new created object like this:
Code: Select all
var objectNode = CreateObject(Server.DefaultRequestContext, settings);
objectNode.Write(6525, "test value"); //NO LUCK, can't see any default values set
Code: Select all
var settings = new CreateObjectSettings
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = jhObjectId,
BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
DisplayName = "a name",
TypeDefinitionId = objectTypeNodeId,
NodeData = new Dictionary<string, string>
{
{"myobject.status_description", "god help me"}, //using the full identifier objectname.variablename
{"status_description", "god help me"}, //using only the variable name
}
};
var objectNode = CreateObject(Server.DefaultRequestContext, settings);