Sales order form changes

Hi!

I added a cancel order button in sales order form, when we click this button sales order will get canceled but here I need to restrict that if any of the lines is delivered it will not allow to cancel the order…

My coding on Clicked method is:

void clicked()
{
    Dialogbutton db1,db2,db3,db4;
    ;
    if(SalesTable.SalesStatus==SalesStatus::Backorder)
    {
        db1 = box::yesNo("Do you want to Cancel PO?", dialogButton::No, "Cancel Order");
        if (db1 == dialogButton::Yes)
        {
            db2 = box::yesNo("This Will Cancel all the PO, no further activities is possible. Do you want to continue?", dialogButton::No, "Cancel Order Confirmation");
            if(db2 == dialogButton::Yes)
            {
                SalesTable.SalesStatus=SalesStatus::Canceled;
                SalesTable.update();
                SalesTable_ds.refresh();
                info(strfmt("%1",SalesTable.SalesId));
             }
          }
    }
    else if( SalesTable.SalesStatus==SalesStatus::Canceled)
    {
        db3=box::yesNo("Do you want to Open PO again?",dialogButton::Yes,"Revoke Cancel");
        if (db3 == dialogButton::Yes)
        {
            db4= box::yesNo("This Will Open all the PO again. Do you want to continue?", dialogButton::Yes, "Open Order Confirmation");
            if(db4 == dialogButton::Yes)
            {
               SalesTable.SalesStatus=SalesStatus::Backorder;
               SalesTable.update();
               SalesTable_ds.refresh();
               info(strfmt("%1",SalesTable.SalesId));
             }
         }
    }
    else
    {
        info( "Process canceled");

    }

}

How could I change my coding there to restrict the button from canceling the order?

Thanks

I don’t think just updating the salesTable status will cancel it lines. You have to cancel the delivery reminder on all the sales order lines.

How to do that, Kranthi?

Coming back to ur question, u can place a condition and select salesline for the salestable using salesid as the reference with delivered status.

REGARDING THE LOGIC FOR CANCELLING sales order, i don’t think by just updating it works

if(SalesTable.SalesStatus==SalesStatus::Backorder)
{
select … /// finds a record with delivered status

if(salesline.recid)
{
info( “Process canceled as the selected SO is in delivered state”); // place ur own infolog
}
else
{
db1 = box::yesNo(“Do you want to Cancel PO?”, dialogButton::No, “Cancel Order”);
if (db1 == dialogButton::Yes)
{
db2 = box::yesNo(“This Will Cancel all the PO, no further activities is possible. Do you want to continue?”,
dialogButton::No, “Cancel Order Confirmation”);
if(db2 == dialogButton::Yes)
{
SalesTable.SalesStatus=SalesStatus::Canceled;
SalesTable.update();
SalesTable_ds.refresh();
info(strfmt("%1",SalesTable.SalesId));
}
}
}

}

Lines status will get updated as delivered when all the quantities got delivered, but here even in line one quantitiy got delivered it shouldn’t allow to cancel the order…

There is already a function to cancel the entire sales order in AX 2012, i don’t remember if it existed in AX 2009.
If you have AX 2012 , check \Classes\SalesUpdateRemain. You can use the similar logic.

void clicked()
{
    Dialogbutton db1,db2,db3,db4;
    boolean ret;
    ;
    if(SalesTable.SalesStatus==SalesStatus::Backorder)
    {
        while select Salesline where Salesline.SalesId == SalesTable.SalesId
        {
       // info(strfmt("%1 %2",sline.RemainSalesPhysical,sline.SalesQty));
           if( Salesline.RemainSalesPhysical < Salesline.SalesQty || Salesline.RemainSalesPhysical==0)
           {
             Box::warning("Packing slip exists,Can't cancel PO");
             ret = false;
             break;
           }
           else if(!ret)
           {
           db1 = box::yesNo("Do you want to Cancel PO?", dialogButton::No, "Cancel Order");
            if (db1 == dialogButton::Yes)
            {
                db2 = box::yesNo("This Will Cancel all the PO, no further activities is possible. Do you want to continue?", dialogButton::No, "Cancel Order Confirmation");
                if(db2 == dialogButton::Yes)
                {
                    ttsbegin;
                    Salesline.SalesStatus=salesstatus::Canceled;
                    SalesTable.SalesStatus=SalesStatus::Canceled;
                    SalesTable.update();
                    SalesLine.update();
                    ttscommit;
                    SalesTable_ds.research();
                    SalesLine_ds.research();

                    info(strfmt("%1",SalesTable.SalesId));
                 }
              }
            }
    }
    }

I’m trying like this, but when I click the cancel order button for deliver remainder existing order that warning message is showing correctly.

When I click the button for open order for SO-107974 its running continuously until the last order, how should I modify it?

also line status isn’t updating to canceled

No, Kranthi.
There is no such class in 2009 and I don’t have AX 2012…

See the example code that can be used to cancel the sales order lines in a sales order,

while select forupdate salesLine
where salesLine.SalesId == salesTable.SalesId
&& salesLine.SalesStatus == SalesStatus::Backorder
{
salesLine.RemainSalesPhysical = 0;
salesLine.RemainInventPhysical = 0;
salesLine.write();
}

void clicked()
{
    Dialogbutton db1,db2,db3,db4;
    boolean ret;
    InventTrans inventtrans;
    ;
    if(SalesTable.SalesStatus==SalesStatus::Backorder)
    {
           select Salesline where Salesline.SalesId == SalesTable.SalesId;

       // info(strfmt("%1 %2",sline.RemainSalesPhysical,sline.SalesQty));
            //if(salesLine.remainSalesFinancial != 0 && inventtrans.StatusIssue == StatusIssue::Deducted)
           if( Salesline.RemainSalesPhysical < Salesline.SalesQty || Salesline.RemainSalesPhysical==0)
           {
             Box::warning("Packing slip exists,Can't cancel PO");
             ret = false;
             break;
           }
           else if(!ret)
           {
           db1 = box::yesNo("Do you want to Cancel PO?", dialogButton::No, "Cancel Order");
            if (db1 == dialogButton::Yes)
            {
                db2 = box::yesNo("This Will Cancel all the PO, no further activities is possible. Do you want to continue?", dialogButton::No, "Cancel Order Confirmation");
                if(db2 == dialogButton::Yes)
                {
                   ttsBegin;
                   while select forupdate salesLine
                        where salesLine.SalesId == salesTable.SalesId
                    {
                        salesLine.RemainInventPhysical = 0;
                        salesLine.RemainSalesPhysical  = 0;
                        salesLine.update();
                    }
                    ttscommit;
                    SalesTable_ds.research();
                    SalesLine_ds.research();

                 }
                 else
                 {
                    info("Cancel order process stopped");
                 }
              }
              else
              {
                info("Process canceled");
              }

            }
    }

    else if( SalesTable.SalesStatus==SalesStatus::Canceled)
    {
        db3=box::yesNo("Do you want to Open PO again?",dialogButton::Yes,"Revoke Cancel");
        if (db3 == dialogButton::Yes)
        {
            db4= box::yesNo("This Will Open all the PO again. Do you want to continue?", dialogButton::Yes, "Open Order Confirmation");
            if(db4 == dialogButton::Yes)
            {
               SalesTable.SalesStatus=SalesStatus::Backorder;
               SalesLine.SalesStatus=SalesStatus::Backorder;
               SalesTable.update();
               SalesLine.update();
               SalesTable_ds.research();
               SalesLine_ds.research();
               info(strfmt("%1",SalesTable.SalesId));
             }
             else
             {
                info("Revoke Process canceled");
             }
         }
        else
        {
        info( "Process canceled");
        }

    }

}

Yes, Kranthi. I added this code to cancel the entire order when there is no deliver remainder…

But when one of the line got delivered it shouldn’t allow the order to cancel…

how should i do that?

Check if the sales order has any line that is partially or fully delivered.

select firstonly Salesline where Salesline.SalesId == SalesTable.SalesId
&& (Salesline.SalesStatus == SalesStatus::Delivered
|| Salesline.RemainSalesPhysical != this.SalesQty)

if(SalesTable.SalesStatus==SalesStatus::Backorder)
{
// select Salesline where Salesline.SalesId == SalesTable.SalesId;

// info(strfmt("%1 %2",sline.RemainSalesPhysical,sline.SalesQty));
// if(salesLine.remainSalesFinancial != 0 && inventtrans.StatusIssue == StatusIssue::Deducted)
//if( Salesline.RemainSalesPhysical < Salesline.SalesQty || Salesline.RemainSalesPhysical!=0)
select firstonly Salesline where Salesline.SalesId == SalesTable.SalesId
&& (Salesline.SalesStatus == SalesStatus::Delivered
|| Salesline.RemainSalesPhysical != Salesline.SalesQty);
Box::warning(“Packing slip exists,Can’t cancel PO”);
ret = false;
break;
}
else if(!ret)
{
db1 = box::yesNo(“Do you want to Cancel PO?”, dialogButton::No, “Cancel Order”);
if (db1 == dialogButton::Yes)
{
db2 = box::yesNo(“This Will Cancel all the PO, no further activities is possible. Do you want to continue?”, dialogButton::No, “Cancel Order Confirmation”);
if(db2 == dialogButton::Yes)
{
ttsBegin;
while select forupdate salesLine
where salesLine.SalesId == salesTable.SalesId && salesLine.SalesStatus == SalesStatus::Backorder
{
salesLine.RemainInventPhysical = 0;
salesLine.RemainSalesPhysical = 0;
salesLine.update();
}
ttscommit;
SalesTable_ds.research();
SalesLine_ds.research();
}

Its showing that warning for delivered order but when I try to delete an open order it’s showing the warning again not allowing me to cancel…

You are not checking anything for this warning.

Don’t you need to add an if before that?

If (salesLine.RecId)

Functionality to cancel the sales orders are exist in AX 2009.
Sales Order Details → Functions Button(footer) → Delivery Remainder → It will opens form update remaining quantity → Click OK button.

That is for a single line. The requirement here is to cancel the entire sales order.