Can someone tell me the correct values for the AssocPropItem for this function?
VB.NET sample snippet:
' Get the Associatin Property Definitions
Dim definitions() As AssocPropDef = m_serviceManager.PropertyService.
GetAssociationPropertyDefinitionsByType(AssociationPropClass.ItemBOMLink)
Dim definition As AssocPropDef = definitions.FirstOrDefault(Function(p) p.DispName.Equals("Test"))
If definition Is Nothing Then
Dim definitionInfo As AssocPropDefInfo = m_serviceManager.PropertyService.
AddAssociationPropertyDefinition(Guid.NewGuid.ToString("D").ToLower, "Test",
DataType.String, True, Nothing, Nothing,
AssocPropTyp.ItemBOMAssoc)
definition = definitionInfo.PropDef
End If
' Set up the Association Property array to add to the specific item BOM
Dim itemBOM As ItemBOM = m_serviceManager.ItemService.GetItemBOMByItemIdAndDate(
m_selectedItem.Id, m_selectedItem.EffEnd, BOMTyp.Tip, BOMViewEditOptions.Defaults)
Dim ParIds As List(Of Long) = New List(Of Long)
Dim associations AsList(OfAssocPropItem) = NewList(OfAssocPropItem)
Dim ChildIds As List(Of Long) = New List(Of Long)
For Each itemAss As ItemAssoc In itemBOM.ItemAssocArray
ParIds.Add(itemAss.ParItemID)
ChildIds.Add(itemAss.CldItemMasterID)
Dim association As AssocPropItem = New AssocPropItem With {
.AssocPropTyp = AssocPropTyp.ItemBOMAssoc,
.FromId = itemAss.ParItemID,
.ToId = itemAss.CldItemMasterID,
.PropDefId = definition.Id,
.Val = "ABC",
.ValTyp = DataType.String
}
associations.Add(association)
Next
' Update item BOM association properties
m_serviceManager.ItemService.UpdateItemBOMAssociationProperties(associations.ToArray(), Nothing)
' Get the item BOM association properties
Dim PropIds As List(Of Long) = New List(Of Long)
PropIds.Add(definition.Id)
Dim assocProps() As AssocPropItem = m_serviceManager.ItemService.GetItemBOMAssociationProperties(
ParIds.ToArray(), PropIds.ToArray(), ChildIds.ToArray())
C# sample snippet:
try
{
IWebServiceCredentials credentials = new UserPasswordCredentials(
"localhost", "Vault", "Administrator", "");
using (WebServiceManager serviceMgr = new WebServiceManager(credentials))
{
AssocPropDef[] definitions = serviceMgr.PropertyService.
GetAssociationPropertyDefinitionsByType(AssociationPropClass.ItemBOMLink);
AssocPropDef definition = definitions.FirstOrDefault(p => p.DispName.Equals("Test"));
if (definition == null)
{
AssocPropDefInfo definitionInfo = serviceMgr.PropertyService.
AddAssociationPropertyDefinition(Guid.NewGuid().ToString("D").ToLower(),
"Test", DataType.String, true, null, null, AssocPropTyp.ItemBOMAssoc);
definition = definitionInfo.PropDef;
}
Item parentItem = serviceMgr.ItemService.
GetLatestItemByItemNumber("100003"),
childItem = serviceMgr.ItemService.GetLatestItemByItemNumber("100013");
AssocPropItem association = new AssocPropItem()
{
AssocPropTyp = AssocPropTyp.ItemBOMAssoc,
FromId = parentItem.Id,
ToId = childItem.MasterId,
PropDefId = definition.Id,
Val = "ABC",
ValTyp = DataType.String,
};
serviceMgr.ItemService.UpdateItemBOMAssociationProperties(
new AssocPropItem[] { association }, null);
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
Hello, Barbara,
the example does not work with current versions - could you please provide an example working with 2017?
Thanks!
Marco