Hi,
I'm building an automation script that get fed an name which is then lookup op in an DOM definition:
var customerfilter = DomInstanceExposers.FieldValues.DomInstanceField(McrCustomerIds.Fields.General.CompanyName()).Equal(jsonJob.customer);
var mcrCustomerList = mcrCustomerdomHelper.DomInstances.Read(customerfilter);
if (mcrCustomerList.Count < 1)
{
error = error + "Customer doesn't exist" + System.Environment.NewLine;
}
else if (mcrCustomerList.Count > 1)
{
error = error + "Multiple customers found with this name, please define name beter" + System.Environment.NewLine;
}
Al i need is the guid of that instance to be inserted into an other DOM definition, now i ran into an issue since i need to provide an GUID. so i load the first entry.
DomInstanceId customer = mcrCustomerList[0].ID;
But this returns an DomInstanceId instead of an GUID. How can i go from this to an guid? i tried:
mcrCustomerList[0].ID.ToString(); (returns cryptic C-sharp error which is nowhere defined or findable)
Convert.ToString(mcrCustomerList[0].ID); which yields an string with the correct id however it is enclosed by another string: DomInstanceId[b78bfed1-ab88-4ba8-b468-c4bb2c809f12]
Now i can do some formating on the later, but i suspect there is an proper way to get the GUID without resorting to regex.
The DOMInstanceID class has two public properties:
- Guid Id
- String ModuleId
So in your case you can get the underlying Guid by using mcrCustomerList[0].ID.Id.
Note that the ModuleId is useful when you don't know the underlying module which contains the DOM instance. However, in most situations the module is known upfront and there is no need to use the ModuleId.
Ah yes that worked