1

I have a button on VendOpenTrans and implemented its clicked method.

I thought this would work but i get an exception and AX closes..

void clicked()
{
   LedgerJournalTrans ledgerJournalTrans;
   VendTransOpen vto;

   super();

   switch (originator.TableId)
   {
      case tableNum(LedgerJournalTrans):
          ledgerJournalTrans = element.args().record();
    }



for ( vto = vendTransOpen_ds.getFirst(0); vto; vto = vendTransOpen_ds.getNext() )
{
    //vendTransOpen_ds.markRecord(vto, 1);
    if (vto.RecId)
    {
        if (manager.getTransMarked(vto) == NoYes::No)
        {
           select Invoice from vendTrans
               where vto.AccountNum == vendTrans.AccountNum &&
                 vto.RefRecId == vendTrans.RecId;

              if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
              {
                // Mark transaction for settlement
                 showError = NoYes::No;
                 manager.updateTransMarked(vto, NoYes::Yes);
                 showError = NoYes::Yes;
              }
          }
      }

    // Update dynamic controls & refresh form as auto-redraw is not triggered
     element.updateDesignDynamic();
     element.redraw();

 }
vendTransOpen_ds.refreshEx(-2);
}

If i comment out the following lines it will work, basically marking all the lines in the grid.

//select Invoice from vendTrans
     //where vto.AccountNum == vendTrans.AccountNum &&
          //vto.RefRecId == vendTrans.RecId;

//if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
//{
     // Mark transaction for settlement
        showError = NoYes::No;
        manager.updateTransMarked(vto, NoYes::Yes);
        showError = NoYes::Yes;
//}

So, to be more clear, what stays is: manager.updateTransMarked(vto, NoYes::Yes);

and this way, it works. As far as i see something happens when i add that select.

Using debug i was able to check it and i think the exception is thrown by the for loop ..

Is there any chance to get a hint about this ?

Olaru Mircea
  • 2,570
  • 26
  • 49

1 Answers1

2

Try changing your for loop definition to this:

for (vto = vendTransOpen_ds.getFirst(0) ? vendTransOpen_ds.getFirst(0) : vendTransOpen_ds.cursor(); vto; vto = vendTransOpen_ds.getNext())

And change this:

select Invoice from vendTrans
    where vto.AccountNum == vendTrans.AccountNum &&
          vto.RefRecId == vendTrans.RecId;

    if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
    {

To this:

if (ledgerJournalTrans.Invoice == vto.vendTrans().Invoice)
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • It worked exactly as you said. Thanks a lot, but can you explain a little the for loop? – Olaru Mircea Dec 17 '15 at 17:47
  • The `?` and `:` are for a ternary operation (see https://msdn.microsoft.com/en-us/library/aa552755.aspx?f=255&MSPPError=-2147217396). So if `getFirst()` doesn't return a value, it uses the cursor. – Alex Kwitny Dec 17 '15 at 18:59