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

  • +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

    The child was in the collection, but I like the GetDataSources trick you shared.  That will come in handy for sure.  You were onto the problem when you noticed my getvalue wasn't in the table.  Once I noticed I had the field name wrong, all went as expected.  Here is the final code to populate a UDF field post validating the change of country code on the ar customer record.  

    '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 udf_repcode

    '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 = oBusObj.SetValue("UDF_ALT_COUNTRY_CODE$","TE")

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

    oCountry = oSession.GetObject("SY_Country_BUS")

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


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

    retVal = oCountry.Find(CountryCode)

    retVal = oCountry.GetValue("AlternateCountryCode",AltCountryCode)

    retVAl = oScript.DebugPrint("GOT HERE 3. CountryCode:" & CountryCode & " Alt: " & AltCountryCode)

    End If

    retVAl = oScript.DebugPrint("GOT HERE 4. CountryCode:" & CountryCode & " Alt: " & AltCountryCode)

    retVal = oBusObj.SetValue("UDF_ALT_COUNTRY_CODE$",AltCountryCode)

    'retVal = oScript.DebugPrint(oBusObj.LastErrorMsg)
    retVal = oScript.DebugPrint("GOT HERE 6. retVal:" & retVal)

    End If

  • 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

  • 0 in reply to Kevin Acorace

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

  • 0 in reply to jepritch

    Thanks for the response!  Using that still gets me this error:

  • 0 in reply to Kevin M

    Thanks for the screenshot and response, but I still can't get past that set line.  I have a debug message line right after and the error comes before that message line.  My set line is exactly like yours   I appreciate you taking the time to respond, but I'm stumped.  I think I might just go with what is working, and not spend any more time on this.  Thanks all!!