Get ExtendedItemDescription for a Sales Order line (Sales Order has not been saved yet)

SOLVED

Experts,

I am looking for a way to retrieve the ExtendedItemDescription for a line item on a Sales Order before the SO is actually saved. The Extended Description gets put together by JobOps, and I need to grab it to extract some data from there.

I can't use "Set oExtDesc = oSession.AsObject(oSession.GetObject("CI_ExtendedDescription_svc"))" because the SO Line specific Extended Description only exists in memory at this point.

I found the below conversation by and   around the HdrExtDescriptionText$ variable, but that is in regards to writing the ExtDesc. I need to retrieve it from memory.

(+) SetValue for ItemCodeDesc$ creating extended descriptions... - Sage 100 Business Object Interface - Sage 100 - Sage City Community

Does anyone have an idea on how to get the Ext Desc from memory?

The script is running on a post validate event of a line field.

Best,

B.

  • +1
    verified answer

    The following should work but ExtDescriptionText$ only seems to be populated when the description is modified on the fly and it is greater than 30 characters..

    oBusObj.GetValue "ExtDescriptionText$", variable

    A more complete way to check for the extended description, including both the on the fly description and the item's description is below.

    sExtendedDescriptionKey = "" : oBusObj.GetValue "ExtendedDescriptionKey$", sExtendedDescriptionKey
    oScript.DebugPrint "sExtendedDescriptionKey: " & sExtendedDescriptionKey
    sOTFExtendedDescriptionText = "" : oBusObj.GetValue "ExtDescriptionText$", sOTFExtendedDescriptionText
    oScript.DebugPrint "sOTFExtendedDescriptionText: " & sOTFExtendedDescriptionText
    nExtendedDescriptionBusiness = 0 : nExtendedDescriptionBusiness = oBusObj.ExtendedDescriptionBusiness
    oScript.DebugPrint "nExtendedDescriptionBusiness: " & nExtendedDescriptionBusiness
    If sExtendedDescriptionKey <> "" And sExtendedDescriptionKey <> "0000000000" Then
    	If nExtendedDescriptionBusiness <> 0 Then
    		Set oExtendedDescriptionBusiness = oSession.AsObject(nExtendedDescriptionBusiness)
    			If sExtendedDescriptionKey <> oExtendedDescriptionBusiness.GetKey() Then oExtendedDescriptionBusiness.Find sExtendedDescriptionKey
    			sExtendedDescriptionText = "" : oExtendedDescriptionBusiness.GetValue "ExtendedDescriptionText$", sExtendedDescriptionText
    			oScript.DebugPrint "sExtendedDescriptionText: " & sExtendedDescriptionText
    		Set oExtendedDescriptionBusiness = Nothing
    	End If
    End If

  • 0 in reply to David Speck

    Once again a great solution. I believe you have a little typo in your first If Clause. Here is what it should be

    If sOTFExtendedDescriptionText = ""  and the sExtendedDescriptionKey <> "0000000000" Then


    What is the benefit of using

    nExtendedDescriptionBusiness = oBusObj.ExtendedDescriptionBusiness

    over

    SET nExtendedDescriptionBusiness = oSession.AsObject(oSession.GetObject("CI_ExtendedDescription_svc "))


    You are still doing a .Find() to get to the record.

    Here is my version based on Davids example:

    sExtendedDescriptionKey = ""
    retVal = oBusObj.GetValue("ExtendedDescriptionKey$", sExtendedDescriptionKey)
    
    sExtendedDescriptionText = ""
    retVal = oBusObj.GetValue("ExtDescriptionText$", sExtendedDescriptionText)
    
    nExtendedDescriptionBusiness = 0
    nExtendedDescriptionBusiness = oBusObj.ExtendedDescriptionBusiness
    
    If sExtendedDescriptionText = "" And sExtendedDescriptionKey <> "0000000000" Then
    	If nExtendedDescriptionBusiness <> 0 Then
    		Set oExtendedDescriptionBusiness = oSession.AsObject(nExtendedDescriptionBusiness)
    		If sExtendedDescriptionKey <> oExtendedDescriptionBusiness.GetKey() Then
    			retVal = oExtendedDescriptionBusiness.Find(sExtendedDescriptionKey)
    			retVal = oExtendedDescriptionBusiness.GetValue("ExtendedDescriptionText$", sExtendedDescriptionText)
    		End If
    		Set oExtendedDescriptionBusiness = Nothing
    	End If
    End If

  • 0 in reply to BillyVanilli

    Regarding the If clause, that was not a typo but rather a precaution because at one point, the extended description key was blank/null for items that did not have an extended description so it is checking against both the old condition and the new condition.  I don't remember which version Sage made the change to zero pad the extended description key when it did not have an extended description but i ran into at least one case where even after an upgrade, there were still some items that had a blank/null extended description key.  I also recall a case with JobOps where it would add lines to the sales orders with a blank/null extended description key when it should have been zero padding it.  Also, the only reason i was going after the extended description on file for an item was as an example and it was to give you the option to choose between the two after they had both been retrieved, your correction won't let this happen in the event the OTF extended description is modified AND the item already had an extended description on file.

    Regarding the object to use for the extended description, i suppose it doesn't really matter, i just happened to find that object handle but during testing, i noticed it didn't keep up when i moved from one line to another so the Find was needed.  If you rather use your own Svc object, that is fine but if you do, you should consider returning it to a numeric handle so you can drop it at the end of your script or store it into a storage variable using oScript.SetStorageVar so you only have to use GetObject once to initialize the object.  I've encountered inconsistent results amongst various scripts when using GetObject in which in some cases, it would continue to get a new object handle even though a previous iteration of the script had used GetObject.  The way i handle this is using a variation of the following, keep in mind, you can use either the oScript object if the handle only needs to be shared amongst events on the same business object or you can use oSession's ScriptObject if the handle needs to be shared across more than one business object, such as between the header, detail, distribution, etc.

    sMsg = ""
    nIM_AliasItem_Svc = 0 : oScript.GetStorageVar("nIM_AliasItem_Svc", nIM_AliasItem_Svc) : If IsNumeric(nIM_AliasItem_Svc) Then nIM_AliasItem_Svc = Clng(nIM_AliasItem_Svc) Else nIM_AliasItem_Svc = 0
    If nIM_AliasItem_Svc = 0 Then nIM_AliasItem_Svc = oSession.GetObject("IM_AliasItem_Svc")
    If nIM_AliasItem_Svc <> 0 Then
    	oScript.SetStorageVar "nIM_AliasItem_Svc", nIM_AliasItem_Svc
    	Set oIM_AliasItem_Svc = oSession.AsObject(nIM_AliasItem_Svc)
    	
    	' Do stuff here.
    	
    	Set oIM_AliasItem_Svc = Nothing
    Else
    	' Optionally set a message to warn that the object handle could not be retrieved.
    	sMsg = "Unable to get object handle to ""IM_AliasItem_Svc"". Check role security." & vbCrLf & "Last Error Msg: " & oSession.LastErrorMsg
    End If
    
    ' Handle sMsg output here.
    If sMsg <> "" Then
    	' Output to trace window.
    	oScript.DebugPrint sMsg
    	' Output to message box displayed to user. Avoid doing this in a script that might loop through the line from the header as you will aggravate the user unless you use another storage variable to track whether the message has been displayed at least once per new session so they are aware of the issue but will not get repeated messages every time it occurs within the same session.
    	If oSession.UI > 0 Then oSession.AsObject(oSession.UI).MessageBox "", sMsg
    End If

    In the case of a table script, in the event that the object handle could not be created and you want to warn the user about it but not impact their ability to continue data entry, you will likely want to implement another stored variable that you can check in each reiteration of the script so you only display the warning once so you aren't constantly interrupting the user if the script's purpose isn't critical.