Update UDT from CI_Item

SOLVED

After reading a few post about updating UDT's from scripts I am wondering if my events are wrong or do I need to SetKey before SetValue?  In the debug I couldn't get any return values, so I am guessing my events are wrong, I've tried a PRE-WRITE and a POST-READ on the CI_Item. 

If oSession.CompanyCode = "ZZZ" then

sIC = ""
sUK = ""
sVENDOR=""
oUDT=0

retVal = oBusObj.GetValue("ItemCode$", sIC)
r=oScript.DebugPrint("IC: " & sIC)
retVal = oBusObj.GetValue("UDF_UNIQUEKEY$", sUK)
r=oScript.DebugPrint("UK: " & sUK)
retVal = oBusObj.GetValue("PrimaryVendorNo$", sVENDOR)
r=oScript.DebugPrint("VENDOR " & sVENDOR)

IF sVENDOR = "0001904" then

Set oUDT = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus","PO_UDT_ROG_IMPORT_ITEM_MAPPING"))

retVal = oUDT.SetValue("UDF_SANMAR_ITEMCODE$",sUK)
retVal = oUDT.SetValue("UDF_SAGE_ITEMCODE$",sIC)
retVal = oUDT.Write()

End If
End IfIf oSession.CompanyCode = "ZZZ" then

sIC = ""
sUK = ""
sVENDOR=""
oUDT=0

retVal = oBusObj.GetValue("ItemCode$", sIC)
r=oScript.DebugPrint("IC: " & sIC)
retVal = oBusObj.GetValue("UDF_UNIQUEKEY$", sUK)
r=oScript.DebugPrint("UK: " & sUK)
retVal = oBusObj.GetValue("PrimaryVendorNo$", sVENDOR)
r=oScript.DebugPrint("VENDOR " & sVENDOR)

IF sVENDOR = "0001904" then

Set oUDT = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus","PO_UDT_ROG_IMPORT_ITEM_MAPPING"))

retVal = oUDT.SetValue("UDF_SANMAR_ITEMCODE$",sUK)
retVal = oUDT.SetValue("UDF_SAGE_ITEMCODE$",sIC)
retVal = oUDT.Write()

End If
End If

Parents
  • 0

    Ok, so I am not getting to the UDT, I tried a POST-READ and POST-WRITE.  On the trace screen my last message was the sVENDOR value.  

    r=oScript.DebugPrint("VENDOR " & sVENDOR)
    
    	IF sVENDOR = "0001904" then
    
    	oUDT = oSession.GetObject("CM_UDTMaint_bus","PO_UDT_ROG_IMPORT_ITEM_MAPPING")
    	r=oScript.DebugPrint("After GetObject oUDT ")
    	
    		If oUDT <> 0 then
    		
    		Set oUDT = oSession.AsObject(oUDT)
    		else
    		
    		retVal = oSession.AsObject(oSession.UI).MessageBox("", "Access to PO_UDT_ROG_IMPORT_ITEM_MAPPING is required for the ??? script to work.")
    		r=oScript.DebugPrint("After AsObject oUDT ")		
    
    		exit sub

Reply
  • 0

    Ok, so I am not getting to the UDT, I tried a POST-READ and POST-WRITE.  On the trace screen my last message was the sVENDOR value.  

    r=oScript.DebugPrint("VENDOR " & sVENDOR)
    
    	IF sVENDOR = "0001904" then
    
    	oUDT = oSession.GetObject("CM_UDTMaint_bus","PO_UDT_ROG_IMPORT_ITEM_MAPPING")
    	r=oScript.DebugPrint("After GetObject oUDT ")
    	
    		If oUDT <> 0 then
    		
    		Set oUDT = oSession.AsObject(oUDT)
    		else
    		
    		retVal = oSession.AsObject(oSession.UI).MessageBox("", "Access to PO_UDT_ROG_IMPORT_ITEM_MAPPING is required for the ??? script to work.")
    		r=oScript.DebugPrint("After AsObject oUDT ")		
    
    		exit sub

Children
  • 0 in reply to jland47

    So you are getting the "Access to..." error when you try?

    If you add the UDT to the menu, the effective permission is in Role Maintenance... with an old bug related to UDT permissions in scripts, where the first UDT listed in Role Maintenance is checked (instead of the correct table).