Iteration over VendTransOpen - axapta

This happens in Accounts Payable -> Journals -> Payments -> Payment Journal.
I choose to see the Lines for a journal and from Functions I select Settlement. I am not sure if this is the same for everyone else.
So, when clicking Settlement, VendOpenTrans opens. I need to iterate over it, and Mark the records according to the invoice of the previously selected LedgerJournalTrans field.
First of all I have to check the VendOpenTrans fields which I am not able to accomplish.
I have added the following piece of code in the init of VendTransOpen:
VendTrans vt;
vt = vendTransOpen_ds.getFirst(true) as VendTrans ;
while (vt)
{
//Do your thing
vt= vendTransOpen_ds.getNext() as VendTrans ;
}
No elements seem to be present in the vendTransOpen_ds..
Can someone give me a hint about this?
Update 1:
Found this :
Understanding the Settlement Mechanism in Microsoft Dynamics AX
and
Automatic mark a Settlement Transactions on a Payment Journal in AX 2012
I didn't think it would be so damn difficult.. I will start digging tomorrow.

Several things are wrong, but probably my #2 is your main problem.
If you place this code in the init method, the query hasn't been executed yet, so nothing will be there. See https://msdn.microsoft.com/en-us/library/aa608211.aspx
Your code will never enter while (vt) because vt will never have a value as written because VendTrans and VendTransOpen are two different tables that don't support inheritance.
The only reason vt = vendTransOpen_ds.getFirst(true) as VendTrans ; doesn't throw an error is because FormDataSource.getFirst()/getNext() returns a Common table record.
What Jan said too.

First off, use getFirst(0) before using getNext().
The zero indicates you want all records rather than marked.
Search, use cross reference tool, or google to get lots of references for the use of these functions.

Related

Get Requsition ID based on PO

In FSCM I am looking to modify the Search view on Add/Update PO page (Main Menu--> Purchasing--> Purchase Orders--> Add/Update POs) to display the Requisition ID associated with the PO in the search results page. The only table I have found that has both PO_ID and REQ_ID is PS_PO_LINE_DISTRIB however unless I use a SELECT DISTINCT clause I will get multiple PO_ID rows when there are more than 1 line on a PO.
Within Purchase Order Inquiry you can see the related Requisition ID's related to a PO by clicking on Document Status link inside the Purchase Order inquiry details page.
I started looking at the PeopleCode within the the Purchase Order Inquiry to see how they are linking the PO to a Requisition and it appears to use work tables with related PeopleCode function libraries, but I wasn't able to figure our how they get linked. I am hoping someone else may know the answer to this. Thank you.
I'm on an old version of PeopleSoft (SCM 8.80, Tools 8.51), so your mileage may vary. I'm assuming you're familiar with App Designer. If not, comment below and I'll add some details about what I'm clicking on.
Find the name of the Add/Update PO component.
Open the PURCHASE_ORDER component in App Designer. Now let's find the name of the search record. Note that there is a different record for the Add Search Record, so if you want to change that too, do all of this for that record as well.
Open the PO_SRCH record, and add the REQ_ID field to it. Make sure you mark the field as a key. You should consider saving your modified PO_SRCH under a new name in case you want to be able to revert to vanilla PeopleSoft. If you do, change the Search Record in the component to your new record name.
We can see that PO_SRCH is a view. So let's modify the view to pull in REQ_ID from PO_LINE_DISTRIB. As you mentioned above, there doesn't appear to be another table with both PO_ID and REQ_ID, so you'll have to do a SELECT DISTINCT.
We should do a LEFT OUTER JOIN instead of a standard join because if you do a standard join and you enter a purchase order with no lines and save it, then you'll never be able to retrieve that purchase order in this window. Since REQ_ID is a key field, we can't have a null, so we have to do the CASE.
One odd thing that I ran into here was building the view now gave me an error about selecting fewer columns in the SQL than I had in my record definition. I solved it by modifying the view for SQL Server. I've never had to do that before and I don't know why I had to do it for this specific record. But anyway, I entered the same SQL under the record's "Microsoft SQL Server" definition.
In the properties of PO_SRCH, we can see that it has a related language record. If you're only using one language, you can probably get away without changing this, but I'll do it for completeness. Open PO_SRCHLN. Now add REQ_ID to it (mark it as a key field like you did above), and save it as PO_SRCHLN2 (I'm saving it under a new name so I don't break anything else that may be using PO_SRCHLN).
Edit the SQL the same was as you did above. Note: I didn't have to also change the Microsoft SQL Server definition like I did above. I have no idea why.
Now build PO_SRCHLN2.
Go back to PO_SRCH and change its related language record to PO_SRCHLN2.
Now build PO_SRCH.
Hopefully you didn't get any errors and your search page has the requisition ID in it now. My system doesn't use requisitions so they're all blank in the example below, but the new field is there.

Microsoft Dynamics AX 2012 - Purchase Price

I've been instructed to create a customization on how the Unit Price (Purchline.PurchPrice) is calculated.
Right now when I'm creating a new purchase order and select an item, it simply pulls from the pricing from the released products for that particular item.
For my customization, I'm going to be using 3 variables to determine the pricing.
1: ItemId
2: Current Session Date
3: Customized Field in the Purchase Header
As such, I'll need access to purchline for the ItemId on the current line, and access to purchtable to access my field in the header.
Right now there is a big process for how the pricing gets pulled from released products, how the system checks for discounts, etc.
My question is, can anyone suggest the best class/location to check and modify where my final PurchPrice field gets set and inserted into purchline?
I need this to be basically the last part of the process of how this PurchPrice gets calculated. I've looked around in the PriceDisc & PriceConvert classes, SalesPurchLine map, the modified method of the ItemId field of the form.
AxPurchline doesn't seem to be triggering at all when I put breakpoints in them and create new purchase order lines.
Any help, insight or advice on where it would be the best to make logic changes for the PurchPrice field would be greatly appreciated.
Thanks in advance!
The table Purchline actually has a method called setPriceDisc where the price agreement is set and the line amount is adjusted.
This seems to be the last place where PurchLine.PurchPrice is set.

AX 2012 Vendor Prepayments Posting

There is a new feature called Vendor Prepayments in AX 2012. It basically allows a company to prepay a vendor before the receipt of any goods. This was not there in AX 2009. So a user can basically attach a Prepayment record to a Purchase order and then post something called Prepayment invoice. When goods finally arrive, this Prepayment invoice is then applied to the "Real" Vendor invoice and settled. Its pretty straightforward and i guess logical.
My requirement is to do this Prepayment Invoice posting by code in X++.
If i try to use the PurchFormLetter class like below, it will post the Real invoice, which wont be correct as in the case of prepayments, there is no inventory transactions.
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchTable,
'8001',
systemDateGet(),
PurchUpdate::All,
AccountOrder::None,
NoYes::No,
NoYes::Yes);
I have looked around in AX Dev Guides, on google, on blogs but no help.
Does anybody know this?
I believe you should look into PurchPrepayTable table logic and PurchPrepayTable form. If you are using a single prepayment for a single purchase order then you can link the prepayment with a purchase using PurchPrepayTable.PurchTable.
If you're willing to accomplish that by calling the X++ code, I would recommend:
Check if any PurchPrepayTable exists for the purchase order;
If it does -- update it (please make sure you run all validations before that);
If it does not -- create a new prepayment (please also refer to PurchPrepayTable table methods to make sure your values in prepayment pass all validations).

asp.net multi-row update with gridview control without looping (vb.net)

I'm pretty new to asp.net. I'm building my first real app as a test. using SQL Server 2008 RS, VS Express 2012, IIS7.x and asp.net4.0
We receive Fedex shipment info every night that gets inserted into an MSSQL DB using SSIS. We then import the invoice, do variance matching and book costs to jobs based on the job no in Ref1 field. All this works great. However, the shipping department are supposed to put the ONLY the JobNo in the ref1 field. Of course they don't and there a lot of temps and shipping stations, so we need to fix the data. They'll put JobNo followed by junk, or junk and then the job no. When the costing people are looking at the invoice it's usually obvious what the job no is (e.g. "Samples for job 123" should be "123"). There can be many rows with the same Ref1 that needs editing (e.g 20 cartons with same Ref1). I have an SP with 3 params (OldRef, NewRef, invNo) that updates the Ref no for all records on that invoices:
UPDATE InvoiceLines
SET REF1 = #NewRef1
WHERE InvNo = #InvNo and Ref1 = #OldRef1
I figured a GridView (with an sqldatasource) would be a nice way to present the data. I only show rows where the Ref1 field is invalid, as the user corrects them, the no of records reduces.
I want the user to select a row, edit the Ref1 value and I'd just get the (old) RefNo of the selected row, it's new value, and call my SP with those and the InvNo (from a DropDown that filtered the invoice lines table).
Turns out to be way more difficult/inefficient that I thought.
All the examples I found to do this type of thing, make the user click all the rows and them loop through every row to do an update. Talk about slow and painful. I want to execute a single SP and have all matching rows updated and then refresh the list.
So what I'd like to figure out is how to get the OLD Ref1 (value in Ref1 before the edit - like deleted in an SQL trigger), the NEW Ref1 (edited value that the user typed in Ref1 - like inserted in an SQL trigger) and execute my SP and then refresh the table with the updated value result set.
Am I better off with something other than a grid view, or just using something other than the built in Edit command?
If I do figure out how to do the update, how do I refresh the GridView.
Can anyone point me in the right direction?
On another note, I'm on the fence about switching to C#. Most of the examples I'm finding are in C#. I learned C++ many years ago and read up on C# at weekend. It doesn't seem too difficult. I did find a Microsoft white paper and it pretty much said there's little difference between VB and C# so no real reason to switch. My colleagues do not know C or C#, so I'm just a bit concerned that in the unlikely event they need to help out, they'll be stuck. Any thoughts on this?
Regards
Mark

Inserting invoice transactions with Dynamics AX / Axapta Business Connector

G'day,
OK, I have now rewritten this question totally:
I am trying to import data into Dynamics through the use of the Business Connector (ideally, I would be importing it directly through SQL but I understand that is not a good idea - however I am open to other suggestions). This is to import invoices from a production system into Dynamics / Axapta (v5).
I can code to insert data into the CUSTINVOICETABLE table, which works fine and generates the RECID. However, new invoices just inserted exist without an Invoice ID (until they are posted I understand). However, I need to insert line items into the CUSTINVOICETRANS table as children of the above entry. For this you need to set the INVOICEID field to refer the above as the link to the parent. However, this does not appear possible before the invoice has been posted. Or I may be way off track?
Does anyone have any ideas or can shed any light for me? That would be much appreciated.
Regards,
Steve
To post a "Free text invoice" simply call custPostInvoiceJob.run() method.
You will have have to make the object first, then call a method with your newly created CustInvoiceTable record.
In X++:
custPostInvoiceJob = new CustPostInvoiceJob();
custPostInvoiceJob.updateQueryBuild(custInvoiceTable);
custPostInvoiceJob.run();
You will have to translate that into Business Connector calls in your preferred language.
Ok, it's actually as easy as it should be.
After the insert statement, simply use the get_Field call:
axRecord.Insert();
recID = (long)axRecord.get_Field("RECID");
You insert the line items in the CUSTINVOICELINE table (which uses a PARENTRECID), then upon posting the items get inserted into the CUSTINVOICETRANS table linked to the appropriate invoice number.
I hope this saves someone from having to work this out themselves.
Steve

Resources