Quantcast
Channel: Microsoft Dynamics GP Forum - Recent Threads
Viewing all articles
Browse latest Browse all 32807

GP Web Services - CreateGLTransaction - GLTransactionLine loop

$
0
0

Hello, I'm writing some code to integrate GL transactions to GP.  I can successfully integrate a "single" transaction (debit/credit) into a document with no problem using the example code in the GP Web Services Programming reference.

My problem is that I'm trying to insert multiple transactions into a single GL document. I've created a loop, and I"m building a GLTransactionLine type List, and am successfully able to add each transaction to the list through my loop.  However the only "catch" I have is, each time through the loop, when I assign the debit and credit values,  the command basically updates all previous List entries (not just the one I'm inserting this time through).

For example,  line one has a sale of $20... the List is successfully added with the $20 values.  Now let's loop.... The next transaction has a $50 value, for example.  The list gets the new transaction (for $50), but it also is changing the first List Transaction values to $50 (changing it from the original $20).  Anyway, no matter how many GL lines I add to the list, each list member ends up with the same value (The value of the last transaction processed).

Can you see an error in my code?  Thanks! (note: I'm not including ALL of my code here, just relevent snippets to show you relevant commands):

......

........

// Here is where I declare my GLTransaction type list:

List<GLTransactionLine> lines = new List<GLTransactionLine>();

// Here's my loop (i'm looping through some query results):

foreach (var line in query_Sales_Get)

           {

...........

............

             // Declare new debit and credit lines:

             GLTransactionLine transactionDebitLine = new GLTransactionLine();

             GLTransactionLine transactionCreditLine = new GLTransactionLine();

.......

.......

               // Here are relevant assigning of debit/credit lines,

               // the mnyTotal_Amounts are indeed different here each time through loop:

               transactionDebitLine.DebitAmount = mnyTotal_Amount;

               transactionDebitLine.CreditAmount = zeroAmount;

               transactionCreditLine.DebitAmount = zeroAmount;

               transactionCreditLine.CreditAmount = mnyTotal_Amount;

               // Here is relevant adding of debit/credit lines to List of GLTransactionLines:

               // This is where my problem lies - when these lines are added, the amounts

               // assigned above are assigned to THE ENTIRE LIST - not just the one

               // set of lines I'm adding this time thru the loop:

               lines.Add(transactionDebitLine);

               lines.Add(transactionCreditLine);

           }

......

.......

           // this of course creates the GL entry in GP, which is working. I just have

           // the wrong values as noted above:

           wsDynamicsGP.CreateGLTransaction(transaction, context,

           transactionCreatePolicy);

// basically, the above loops runs great, I end up with a GL document

// with many transactions in it, but ALL transactions end up with the SAME amount.  


Viewing all articles
Browse latest Browse all 32807

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>