Script to retrieve altcountrycode not working

SOLVED

I get an error whenever I try to set the Country Business object, either as a childhandle or asObject.  I have no idea why this keeps getting an error 88.

'Title: UDF_Alt_Country_Code
'Desc: Autofill the UDF_Alt_Country_Code after selecting Country Code
'Bus Object: SY_Country_Bus
'Event: Column post validate on CountryCode

'Version 1.02

retVal = 0
CountryCode = ""
AltCountryCode = ""
oRegion = 0
oCountry = 0

If oSession.CompanyCode = "ADX" OR oSession.CompanyCode = "ZIT" OR oSession.CompanyCode = "ZZZ" then

retVal = oBusObj.GetValue("COUNTRYCODE$",CountryCode)

retVAl = oScript.DebugPrint("GOT HERE 1." & " " & CountryCode & " " & oCountry)

'1st attempt set oCountry = oBusObj.AsObject(oBusObj.GetChildHandle("CountryCode"))

nCountry=0 : nCountry = oSession.GetObject("SY_Country_BUS")

retVAl = oScript.DebugPrint("GOT HERE 2." & " " & CountryCode & " nCountry: " & nCountry)

Set oCountry = oSession.AsObject(nCountry)


retVAl = oScript.DebugPrint("GOT HERE 3." & " " & CountryCode & " " & oCountry)


if oCountry <> 0 then
Set oCountry = oScript.AsObject(oCountry)

retVal = oCountry.Find(CountryCode)
retVal = oCountry.GetValue("AltCountryCode",AltCountryCode)

retVAl = oScript.DebugPrint("GOT HERE 2." & AltCountryCode)

retVal = oBusObj.setvalue("UDF_Alt_Country_Code$",AltCountryCode)

End If

End If

Top Replies

Parents
  • +1
    verified answer

    HI

    How are you invoking this script? 

    Set oCountry = oSession.AsObject(oBusObj.GetChildHandle("CountryCode"))

    The above should be the proper syntax, assuming there is a child collection called CountryCode.  You can get a list of the data sources by doing something like:

    msgbox oBusObj.GetDataSources() ' this should put a list in your message box.

    The second thing I noticed is that the value you are getting from the country table is different.

    retVal = oCountry.Find(CountryCode)

    retVal = oCountry.GetValue("AlternateCountryCode$", AltCountryCode) ' remember the "$" for string values

    Hope that helps, not sure where you are getting the error 88!

    Elliott

  • 0 in reply to jepritch

    I wanted to test seeing the list of data sources, so I added this to my code and it froze and I didn't see a message box on the client or the server.  Not sure why it didn't work.  Any ideas?

    msgbox oBusObj.GetDataSources() 

    Thanks,

    Kevin

  • +1 in reply to Kevin Acorace
    verified answer

    Never use msgbox for Advanced / Premium.  It won't work.  Try this:

    retVal = oSession.AsObject(oSession.UI).MessageBox("", oBusObj.GetDataSources() )

  • 0 in reply to Kevin M

    Can anyone let me know what I am doing wrong with the GetChildHandle code below with the script above?

    Thanks, everyone for responding!  Well, I confirmed that CountryCode is in the list but I still couldn't get the GetChildHandle to work.

    It would be great to figure out what I'm doing wrong for the future, but I did get this working using GetObject.

    This worked:

    oCountry = oSession.GetObject("SY_Country_BUS")

    and this doesn't:

    set oCountry = oBusObj.AsObject(oBusObj.GetChildHandle("CountryCode"))

    Thanks again!

    Kevin

Reply
  • 0 in reply to Kevin M

    Can anyone let me know what I am doing wrong with the GetChildHandle code below with the script above?

    Thanks, everyone for responding!  Well, I confirmed that CountryCode is in the list but I still couldn't get the GetChildHandle to work.

    It would be great to figure out what I'm doing wrong for the future, but I did get this working using GetObject.

    This worked:

    oCountry = oSession.GetObject("SY_Country_BUS")

    and this doesn't:

    set oCountry = oBusObj.AsObject(oBusObj.GetChildHandle("CountryCode"))

    Thanks again!

    Kevin

Children