Open Item Customer Sales History By Period UI from Button Script - pass Customer

SOLVED

Experts,

I am using the button script below to open Customer History by Period from a Sales Order line (Sage has this button in Item Maintenance on the History tab). It works. It opens properly for the item. But there is a secondary selection criterion in the UI for the customer. Is there a way to automatically populate that (ideally as part of the Process method).

If that is not possible, then  I might have to work on one of these workarounds:

1) I could use InvokeChange on the ML_HISTORYCUSTOMER field. But my problem here is that the button is clicked in Sales Order Entry, so I am not sure how I would get a UI Object handle for the freshly opened IM_ItemCustomerHistoryByPeriod_UI.

2) I could use a StorageVar that I populate from the script below, and then I could read that var as part of a UI event script the IM_ItemCustomerHistoryByPeriod_UI. From there I can do the InvokeChange, and reset the StorageVar. Instead of a UI script, I could possibly also use a  Post-Read on the IM_ItemCustomerHistoryByPeriod

Any idea on how to pass the customer, or thoughts on my workarounds?

Thanks,

Bastian

oLines = 0 : sItem = "" : sItemType = ""

Set oLines = oBusObj.AsObject(oBusObj.Lines)
retVal = oLines.GetValue("ItemCode$",sItem)
retVal = oLines.GetValue("ItemType$",sItemType)

If sItemType = "1" Then
	oItemSalesHist = 0
	oItemSalesHist = oSession.GetObject("IM_ItemCustomerHistoryByPeriod_UI")

	If oItemSalesHist <> 0 Then
		Set oItemSalesHist = oSession.AsObject(oItemSalesHist)
		retVal = oItemSalesHist.Process(sItem)
	End if
End If

  • 0

    IM_ItemCustomerHistoryByPeriod_UI doesn't appear to accept any arguments to indicate the customer number. 

    However, AR_CustomerItemHistoryByPeriod does appear to accept the item code in in the first argument, the AR division number in the fifth argument, and the customer number in the sixth argument.

    You should be able to use your workaround to use oSession.ScriptObject's SetStorageVar to set the values of any "arguments" you need set in the post load script and then use oSession.ScriptObject's GetStorageVar in the post load event followed by using the arguments with the UI object's InvokeChange method.

  • 0 in reply to David Speck

    That is amazing. Did you find this in the Object documentation within Sage?

    I am able to properly open Customer Sales History through AR_CustomerItemHistoryByPeriod for the Customer/Item combination. The only issue is that It opens with the Focus in the ItemCode field and that gets blanked out. The description shows properly. Not sure if it is related, but the drill-down button on the right side is greyed out until I move to another item and come back.

    Here is the working example:

    oLines = 0 : sItem = "" : sItemType = ""
    
    Set oLines = oBusObj.AsObject(oBusObj.Lines)
    retVal = oLines.GetValue("ItemCode$",sItem)
    retVal = oLines.GetValue("ItemType$",sItemType)
    
    If sItemType = "1" Then
    	oItemSalesHist = 0
    	'oItemSalesHist = oSession.GetObject("IM_ItemCustomerHistoryByPeriod_UI")
    	oItemSalesHist = oSession.GetObject("AR_CustomerItemHistoryByPeriod_UI")
    
    	
    
    	If oItemSalesHist <> 0 Then
    
    		'Set a StorageVar on the Session Object to share the customer
    		oSessionScript = 0
    		Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    		retval = oSessionScript.SetStorageVar("Btn_Hist_Cust","00-TEST01")
    
    		Set oItemSalesHist = oSession.AsObject(oItemSalesHist)
    		retVal = oItemSalesHist.Process(sItem,"","","","00","TEST01")
    	End if
    End If

    The StorageVar line has no relevance for the AR_CustomerItemHistoryByPeriod version. I used it to test the StorageVar workaround. Unfortunately, InvokeChange doesn't work properly. I am able to retrieve the StorageVar, but the InvokeChange doesn't seem to happen. Not sure if that is a timing issue. Maybe the InvokeChange fires before the UI Element actually exists. I have a MessageBox in there to show me the StorageVar value. That MB pops up before the UI is rendered.

  • 0 in reply to BillyVanilli
    SUGGESTED

    I saw the same thing with the blank item code yet the description was filled. I didn't spend any more time trying to figure out why. You might be able to incorporate both methods and use the UI post load script on the AR_CustomerItemHistoryByPeriod_UI panel to call the oUIObj.PostLoad method to see if that will correct the blank item code and disabled drill down button.

  • +1 in reply to David Speck
    verified answer

    Thanks again for your help on this David! I am using the AR Customer Sales History with the overloads that you had pointed out and I am able to get around the blank Item Code issue with an additional UI script. The UI script also adds the ShipTo code. I don't have the greyed out Drill Down button issue anymore.

    The working solution below:

    The button script (on the lines panel, runs on the server. It creates two shared session variables (ItemCode - needed because it doesn't show properly in the Customer Sales History and ShipToCode).

    oLines = 0 : sItem = "" : sItemType = ""
    sARDiv = "" : sCust = "" : sShipTo = ""
    
    Set oLines = oBusObj.AsObject(oBusObj.Lines)
    retVal = oLines.GetValue("ItemCode$",sItem)
    retVal = oLines.GetValue("ItemType$",sItemType)
    retVal = oBusObj.GetValue("ARDivisionNo$",sARDiv)
    retVal = oBusObj.GetValue("CustomerNo$",sCust)
    retVal = oBusObj.GetValue("ShipToCode$",sShipTo)
    
    If sItemType = "1" Then
    	oARCustSalesHist = 0
    	oARCustSalesHist = oSession.GetObject("AR_CustomerItemHistoryByPeriod_UI")
    
    	If oARCustSalesHist <> 0 Then
    		'Set a StorageVar on the Session Object to share the ItemCode and ShipToCode
    		oSessionScript = 0
    		Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    		retval = oSessionScript.SetStorageVar("Btn_Hist_ItemCode",sItem)
    		If Len(sShipTo) > 0 Then
    			retval = oSessionScript.SetStorageVar("Btn_Hist_ShipTo", sShipTo)
    		End If
    		'Open Customer Sales History for the Customer/Item
    		Set oARCustSalesHist = oSession.AsObject(oARCustSalesHist)
    		retVal = oARCustSalesHist.Process(sItem,"","","",sARDiv,sCust)
    	End if
    End If

    The UI script below fires on the Panel PostLoad event of the  DHISTORYCV panel (IM > Item Maintenance).

    oSessionScript = 0 : sItem = "" : sShipTo = ""
    Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    retval = oSessionScript.GetStorageVar("Btn_Hist_ItemCode", sItem)
    retval = oSessionScript.GetStorageVar("Btn_Hist_ShipTo", sShipTo)
    
    If Len(sItem) > 0 Then
    	retVal = oUIObj.InvokeChange("HISTORYITEMCODE", sItem)
    	retval = oSessionScript.SetStorageVar("Btn_Hist_ItemCode", "")
    End If
    
    If Len(sShipTo) > 0 Then
    	retVal = oUIObj.InvokeChange("HISTORYSHIPTOCODE", sShipTo)
    	retval = oSessionScript.SetStorageVar("Btn_Hist_ShipTo", "")
    End If