-1

I have encountered this error before. It usually means that I am trying to use and method with an empty object. So I put in checks but the checks do not seem to be working. Here is my code:

    possiblechildSet= MXServer.getMXServer().getMboSet("ASSETANCESTOR", userinfo)
    possiblechildSet.setWhere("ANCESTOR='" mbo.getString("ASSETNUM") "' and ASSETNUM !='" mbo.getString("ASSETNUM") "'")
    if (possiblechildSet.count() <> 0) or (possiblechildSet.count() is not None) :
        childSet= mbo.getMboSet("ASSETMISSINGCHILD")
        if childSet.count() is not None:
            childMbo = childSet.getMbo(0)
            childassetnum = childMbo.getString('ASSETNUM') //error

I am getting the error when i attempt to use the getString method. Which is valid. I have used in this way in multiple scripts before hand. I just don't understand how it is getting through my checks. Any help will be appreciated. Thanks Wann

mri3
  • 256
  • 3
  • 18
  • What is the actual attribute error you're receiving? –  Jun 26 '15 at 12:33
  • thank you for replying. the error im getting is AttributeError: 'NoneType' object has no attribute 'getString' in – mri3 Jun 26 '15 at 12:39

1 Answers1

1

Put the check on the next line:

childMbo = childSet.getMbo(0)
if childMbo is not None:
    childassetnum = childMbo.getString('ASSETNUM') 
Eric Levieil
  • 3,554
  • 2
  • 13
  • 18
  • That worked Thank you! If you have the time would you mind explaining why it wasn't happening before? – mri3 Jun 26 '15 at 13:18
  • It is always better to check the exact thing you need: here you want to know if childMbo is None, so test for that. I don't know why "childSet.count() is not None " wasn't working, maybe it was returning 0, maybe it is a special case where childSet.count() and childSet.getMbo(0) are not related. – Eric Levieil Jun 26 '15 at 13:25