Hello,
In my script, I create system roles with associated service items and add them to specifics shops.
Then I want to delete them: I delete first associated shop products, then system roles and service items.
When a system role was resqueted in IT shop, I can not logically delete it and I meet errors.
How can I verify if the system role was requested in IT Shop? In order to not try to delete it.
Below the content of my script.
Regards,
Serge
' ### CREATE
' create service item
Dim AccProduct As ISingleDbObject = Connection.CreateSingle("AccProduct")
AccProduct.PutValue("Ident_AccProduct", DisplayName)
AccProduct.PutValue("UID_AccProductGroup", Connection.GetSingleProperty("AccProductGroup", "UID_AccProductGroup", "Ident_AccProductGroup='RoleApplicatif'"))
AccProduct.FillPrimaryKey()
AccProduct.Save()
' create system role binded to the service item
Dim ESet As ISingleDbObject = Connection.CreateSingle("ESet")
ESet.PutValue("Ident_ESet", Ident_ESet)
ESet.PutValue("DisplayName", DisplayName)
ESet.PutValue("Ident_ESetType", "...")
ESet.PutValue("IsForITShop", True)
ESet.PutValue("UID_AccProduct", AccProduct.GetValue("UID_AccProduct"))
ESet.FillPrimaryKey()
ESet.Save()
' create a product in every concerned shop
If AssociatedShop.Length > 0 Then
Dim ShopList As String() = AssociatedShop.Split(New Char() {"|"c})
Dim ShopItem As String
For Each ShopItem In ShopList
Dim ITShopOrgHasESet As ISingleDbObject = Connection.CreateSingle("ITShopOrgHasESet")
ITShopOrgHasESet.PutValue("UID_ITShopOrg", Connection.GetSingleProperty("ITShopOrg", "UID_ITShopOrg", "FullPath='" & ShopItem & "\Shelf'"))
ITShopOrgHasESet.PutValue("UID_ESet", ESet.GetValue("UID_ESet"))
ITShopOrgHasESet.FillPrimaryKey()
ITShopOrgHasESet.Save()
Next
End If
' assigned to every concerned business role
If AssociatedBusinessRole.Length > 0 Then
Dim BusinessRoleList As String() = AssociatedBusinessRole.Split(New Char() {"|"c})
Dim BusinessRoleItem As String
For Each BusinessRoleItem In BusinessRoleList
Dim OrgHasESet As ISingleDbObject = Connection.CreateSingle("OrgHasESet")
OrgHasESet.PutValue("UID_Org", Connection.GetSingleProperty("Org", "UID_Org", "Ident_Org='" & BusinessRoleItem & "'"))
OrgHasESet.PutValue("UID_ESet", ESet.GetValue("UID_ESet"))
OrgHasESet.FillPrimaryKey()
OrgHasESet.Save()
Next
End If
' ### DELETE
Dim ESet As ISingleDbObject = element_ESet.Create()
' delete all assignations to business role: not mandatory?
'Dim collection_OrgHasESet As IColDbObject = Connection.CreateCol("OrgHasESet")
'collection_OrgHasESet.Prototype("UID_ESet").IsDisplayItem = True
'collection_OrgHasESet.Load(CollectionLoadType.Slim)
'For Each element_OrgHasESet As IColElem In collection_OrgHasESet
'Dim OrgHasESet As ISingleDbObject = element_OrgHasESet.Create()
'If String.Compare(OrgHasESet.GetValue("UID_ESet").String.ToUpper(), ESet.GetValue("UID_ESet").String.ToUpper()) = 0 Then
'OrgHasESet.Delete()
'OrgHasESet.Save()
'End If
'Next
' Delete all asociated products from shops
Dim collection_ITShopOrgHasESet As IColDbObject = Connection.CreateCol("ITShopOrgHasESet")
collection_ITShopOrgHasESet.Prototype("UID_ESet").IsDisplayItem = True
collection_ITShopOrgHasESet.Load(CollectionLoadType.Slim)
For Each element_ITShopOrgHasESet As IColElem In collection_ITShopOrgHasESet
Dim ITShopOrgHasESet As ISingleDbObject = element_ITShopOrgHasESet.Create()
If String.Compare(ITShopOrgHasESet.GetValue("UID_ESet").String.ToUpper(), ESet.GetValue("UID_ESet").String.ToUpper()) = 0 Then
ITShopOrgHasESet.Delete()
ITShopOrgHasESet.Save()
End If
Next
' extract UID of associated service item and delete system role
Dim UID_AccProduct As String = ESet.GetValue("UID_AccProduct").String.ToUpper()
ESet.Delete()
ESet.Save()
' delete associated service item with the extracted UID
Dim collection_AccProduct As IColDbObject = Connection.CreateCol("AccProduct")
collection_AccProduct.Prototype("UID_AccProduct").IsDisplayItem = True
collection_AccProduct.Load(CollectionLoadType.Slim)
For Each element_AccProduct As IColElem In collection_AccProduct
Dim AccProduct As ISingleDbObject = element_AccProduct.Create()
If String.Compare(AccProduct.GetValue("UID_AccProduct").String.ToUpper(), UID_AccProduct) = 0 Then
AccProduct.Delete()
AccProduct.Save()
End If
Next