Page 1 of 1

How do I open a specific Purchase Order?

PostPosted: Fri Aug 21, 2009 10:48 am
by pricerc
Hi,

If I want to open a specific Sales Order from a breakout in another form, I can use the following bit of code :
Code: Select all
MDIParentObject.DrillDownByFormNumber SalesOrderID, 300
(This is actually in the Purchase Order form, and the code was kindly provided by Mike some time ago)

What's the equivalent for opening a specific Purchase Order from a breakout in another form ?

I tried
Code: Select all
MDIParentObject.DrillDownByFormNumber PurchaseOrderID, 400
but it doesn't work; it opens the Purchase Order form, but not the specific Purchase Order. I think I also tried using the Purchase Order number (rather than the ID), also without success.

/Ryan

Re: How do I open a specific Purchase Order?

PostPosted: Mon Aug 24, 2009 7:57 pm
by Mike.Sheen
pricerc wrote:...
I tried
Code: Select all
MDIParentObject.DrillDownByFormNumber PurchaseOrderID, 400
but it doesn't work; it opens the Purchase Order form, but not the specific Purchase Order. I think I also tried using the Purchase Order number (rather than the ID), also without success.

/Ryan


Hi Ryan,

You're spot on your syntax - that should work. I've gone and checked in the code, and as long as your PurchaseOrderID is valid, AND the MIDParentObject is valid, then it should work.

Perhaps you mispelt the MDIParentObject, or whatever breakout you're invoking from has given you an invalid one - specifically which breakout are you trying to load the purchase order form from ?

Re: How do I open a specific Purchase Order?

PostPosted: Tue Aug 25, 2009 12:56 pm
by pricerc
Thanks Mike.

Turns out my mai problem was my PurchaseOrderID - I had some code that was trying to use a P/O number stored in a notes field to load the Purchase Order into a clsPOrder; although ReadOrder was returning a -1, it seems it wasn't actually reading any order (?).

Anyway, I now suspect that the P/O ReadRecord requires an ID not an Order Number ? (I'd originally copied the logic from the P/O screen that was opening its Sales Order, and hadn't fully tested my code, assuming that the -1 from the ReadRecord meant that I had the right record loaded.... :oops: )

Since all I actually wanted was the OrderID, I switched to using a SQL query to get it, and this now works.

Only one question remains: it works fine if the P/O screen isn't already open - it opens the screen at the right order. However, if the screen is already open, it doesn't move to the one I've specified, which opening the SalesOrder screen does (as in the original code you sent me).

/Ryan

Re: How do I open a specific Purchase Order?

PostPosted: Tue Aug 25, 2009 1:43 pm
by pricerc
Update:

I switched off the 'reuse Windows' option, and the P/O now seems to opening correctly; of course in a new Window, which is fine for me, not sure if it'll be fine for the client though.

I don't think I changed anything else...

/Ryan

Re: How do I open a specific Purchase Order?

PostPosted: Mon Aug 31, 2009 8:10 pm
by Mike.Sheen
pricerc wrote:it works fine if the P/O screen isn't already open - it opens the screen at the right order. However, if the screen is already open, it doesn't move to the one I've specified, which opening the SalesOrder screen does (as in the original code you sent me).

/Ryan


Hmm... sounds like a bug. If you can provide me with what I need to do to reproduce the problem with demo data I'll log it direct into our bug tracking database.

Re: How do I open a specific Purchase Order?

PostPosted: Wed Sep 02, 2009 11:27 am
by pricerc
Mike,

demonstrating the problem is fairly easy. here are the steps for setting up the same data:

1) add a 'Related Purchase Order' note type to Sales Orders.

2) in S/O Custom Menu Clicked replace the end of the sample script with this bit of code:
Code: Select all
   ElseIf MenuIndex = 3 Then
       Set SO = SalesOrderObject
        For Each note In SO.Notes
           If note.NoteTypeKey = "kAA6D045C-9753-49B1-800A-835BB6216279" Then
              'related PO
               PurchaseOrderID = Trim(GetPOrderID(SO.database, note.NoteText))
               If PurchaseOrderID <> "" Then
                  ' MsgBox PurchaseOrderID
                  MDIParentObject.DrillDownByFormNumber PurchaseOrderID, 400
               End If
               Exit For
           End If
       Next
   End If
End Sub

Function GetPOrderID(database, poNumber)
   GetPOrderID = ""
   With database
       Dim SQL
       Dim ReadHandle
       
       ReadHandle = CInt(.StatementOpen(.ConnectionRead1, False, "", 1))
       SQL = "SELECT OrderID FROM PO_Main WHERE OrderNo=" & database.FormatChar(poNumber)
       If .ExecuteSelect(CInt(ReadHandle), CStr(SQL)) <> 0 Then
            .BindMem CInt(ReadHandle), CInt(1), vbString
            If .FetchRow(CInt(ReadHandle)) = True Then
                GetPOrderID = CStr(.GetData(CInt(ReadHandle), CInt(1)))
            End If
       End If
       .StatementRenew CInt(ReadHandle)
   End With
End Function


(You will need to replace the GUID for the note type with the relevant UID out of the database)

3) (optional, but recommended) in Form Loaded breakout, change the label for menu item 3 to say 'Open Related Sales Order'.

4) Pick any Purchase Order other than the last one on the P/O form (I used 100339 for my test). Not really important for the purposes of this test, but if like me you like test data to more-or-less make sense, you may want to make a note of a part number on the order.

5) Create a new Sales Order, and in the Notes Tab, add a new 'Related Purchase Order' note, and put the P/O number in the note text.

6) Save the order.

Once the data is there test as follows:

1) Make sure all instances of P/O form are closed.

2) Open the Sales Order you just created.

3) pick 'Open Related Purchase Order' from the Record menu. It will open the P/O specified.

4) While still in Purchase Orders. Move to last (or first) record. Well any record other than the one you specificed in the S/O.

5) Leave P/O window open and go back to S/O and try the menu item again. It will go to the P/O screen, but not drill to the specified P/O ID.

Re: How do I open a specific Purchase Order?

PostPosted: Mon Oct 19, 2009 3:04 pm
by Mike.Sheen
Confirmed as a bug in 06.05.13.

Has been now fixed in 06.05.14. See bug #7226 (http://jiwa.com.au:81/bugzilla/show_bug.cgi?id=7226).