Window element does not exist or already exists in a button script

Tearing my hair out on this one.

My goal is to look through detail purchase order detail lines looking for specific inventory items. 

This is a button script on the Inventory Item Maintenance Screen.  Sage 100 2018 Advanced (script is set to run on the server and allow external access is enabled for the company).

Unfortunately when I start to step through the records (MoveFirst) I get:

Error 65   Window element does not exist or already exists

Program PO_COMMONENTRYDETAIL.PVC

Statement 863

Class PO_PurchaseOrderDetail_bus

Method  GetWarehouseQty

Note really sure how GetWarehouseQty is involved?

Relevant portion of the script is as follows:

' obtain access to Purchase Order Detail Line file

 oPOLine = OSession.Getobject("PO_PurchaseOrderDetail_bus")
 retval = oSession.AsObject(oSession.UI).Messagebox("POLine value is " & oPOLine )  ' returns 100089

 if oPOLine <> 0 then
  set oPOLine = oSession.Asobject(oPOline)

  retval = oPOLine.SetIndex("KITEMWHSE")    'searching for items by the itemcode so use this index
  retval = oSession.AsObject(oSession.UI).Messagebox("return value from setindex " & retval )  'no error here

  retval = oPOLine.SetBrowseFilter(itemcode)
  retval = oSession.AsObject(oSession.UI).Messagebox("return value from setbrowsefilter " & retval )  'no error here
  
  retval = oPOLine.MoveFirst()     <== ERROR OCCURS HERE

....  (details omitted)

END IF

Originally I did not use the SetIndex or SetBrowseFilter and got the same error.

Is it possible I have to open the PO_Header object as well?

Ideas?

  • 0

    Out of curiosity, I modified the script to step through PO header records and it works just fine?

    So MoveFirst and MoveNext don't work for detail line objects???

  • 0

    Try the following:

    change Getobject("PO_PurchaseOrderDetail_bus") to Getobject("PO_PurchaseOrderDetail_svc")

    change SetIndex("KITEMWHSE")  to SetBrowseIndex("KITEMWHSE","KITEMWHSE") 

  • 0 in reply to TomTarget

    I'd wonder if the problem comes from a new order not being saved and available to access the lines that way?  Have you tried the normal way to open a Lines object from within a header script?

    Set oLines  = oSession.AsObject(oBusObj.Lines)

  • 0 in reply to Kevin M

    That's kind of my suspicion too.

    Trying to avoid having to open every PO header to get to all the detail lines.

    The overall problem I'm trying to solve is that the client is changing valuation from average cost to serial costing for a large number of items.  Some of these have POs and SOs and it appears that during the valuation change the valuation field on the PO and SO detail lines do not get changed.  It's no issue if you do a receipt of goods via standard data entry,  however the client just acquired Scanco.   When you scan the items into the warehouse from receiving it does ask for the serial number,  but when it gets imported to receipt of goods it drops the serial number because the PO line still shows average cost.  Disappointed

    So the goal is to hunt through the PO lines looking for the specific items to be changed.  Hence,  a button script from item maintenance so oBusOBJ would be pointing to CI_item not the purchase order header.

    And since I need to modify the value I have to use the BUS object and not the SVC object.

  • 0 in reply to TomTarget

    That sounds like a bug in the utility.

    Can you run a VI import to change the values instead of using a script?

  • 0 in reply to Kevin M

    Definitely a bug.  The bar code import unfortunately doesn't self correct the valuation field in the po like the regular data entry does.

    Due to the large number of items being changed (which pretty much have to be done one at a time - client has five locations - and inventory valuation change to serial forces you to zero out the inventory first - then you physical count to get the serial numbers in - and unfortunately it doesn't update the PO's),  the VI approach would be very cumbersome.

  • 0 in reply to Steve Passmore

    Will try this to see if I can at least navigate, but the problem is going to be that I need to change a value, so I really need BUS.

  • 0 in reply to TomTarget

    You can use the service object to efficiently browse for the item in the p/o lines and then use an instance of PO_PurchaseOrder_bus to modifiy the record.  For my example the object handle is poBusObj for the P/O business object and poSvcObj for the P/O detail service object..

    When the browse has found a record do a poSvcObj'GetValue("PurchaseOrderNo$",<variable for p/o>) and then do a poBusObj'SetKey(<variable for p/o>).  Once the header record is set you can do poBusObj'Lines'EditLine( poSvcObj'GetKey$("KDISPLAY"))

    The record can then be changed through the business object.  Remember to commit the line change with poBusObj'Lines'Write() and then commit the purchase order changes with poBusObj'Write()

    Continue looping through the service object until EOF.

  • 0 in reply to Steve Passmore

    OK.  Looks like change to using the SVC object has eliminated the error.

    Continuing on with the rest of the project.

    Thanks for the input Steve!