04-06-2013 03:25 PM
Dear all,
I would need to assign a level of risk (sRisk) to an application (ApplicationName).
I get an error on type ojbect assigned to the method is not the right one.
Do someone could help me to bring the adequat modifications?
Thanks
sAppName = "ApplicationName"
sRisk = "Medium"
'Get application collection
Set oAppli = lApplis.Item(sAppName)
'Quality test
sEmpty = oAppli.GetID
If sEmpty > 0 Then
ctr = oAppli.GetCollection("Risque").Count
If (ctr > 0) Then
For Each oItem In oAppli.GetCollection("Risque")
oItem.Remove
Next
End If
'Get Risk collection
Set oRisk = lRisks.Item(sRisk)
'Set the reference of the risk to the application and remove the existing ones
oAppli.GetCollection("Risque").Add (oRisk.GetID)
End If
Solved! Go to Solution.
04-06-2013 04:14 PM - edited 04-06-2013 04:16 PM
Hello Benoit,
you have 2 errors in your code.
First, the way you disconnect risks from an application will disconnect only half of the risks... which means it will work only if you have one risk attached to your application.
Then, since in your code oRisk is already a megaObject, you should not use the "getid".
Your code should look like this :
sAppName = "ApplicationName" sRisk = "Medium" 'Get application collection Set oAppli = lApplis.Item(sAppName) 'Quality test sEmpty = oAppli.GetID If sEmpty > 0 Then ctr = oAppli.GetCollection("Risque").Count If (ctr > 0) Then 'This code will not work : it will disconnect only half of the risks attached to the application 'For Each oItem In oAppli.GetCollection("Risque") 'oItem.Remove 'Next 'Use this code instead colRisques = oAppli.getCollection("Risque") For i = 1 to colRisques.count colRisques.item(1).remove Next End If 'Get Risk collection Set oRisk = lRisks.Item(sRisk) 'Set the reference of the risk to the application and remove the existing ones 'Since oRisk is already a MegaObject, the ".getId" has nothing to do here :-) oAppli.GetCollection("Risque").Add (oRisk) End If
PS : and I guess you defined lApplis and lRisks somewhere else in your code 🙂
Regards,
Lionel