Skip to main content
Solved

Is it possible to throw Error in a Method?


Atiq
Jr Varsity III
Forum|alt.badge.img
  • Jr Varsity III
  • 38 replies

Hi,

 i have created a Methord that Pulls Soline items, i want to throw Error for certain conditions in that methord, How can we Achive that?

Best answer by Atiq

Hi Vignesh,  

i have written the logic to bring the soline values from artran,  and using Saleorderval(tran1,line1); method,  iam populating the error

 public virtual IEnumerable invFilter(PXAdapter adapter)
        {

            var x = AlternateInvId.Select().Count;
            var q = Invview.Select().Count;
            var s = Lineqty.Select().Count;


            var k = Invview.AskExt();
            if (this.Invview.AskExt() == WebDialogResult.OK)
            {
                foreach (ARInvoice invoice in Invview.Select())

                {
                    if (invoice.Selected == true)
                    {

                        try
                        {
                            foreach (SOLine sO in Lineqty.Select())
                            {
                                var kb = sO.InvoiceNbr;
                                var aa = sO.OrderNbr;
                            }

                            foreach (ARTran tran1 in PXSelect<
                                ARTran,
                                Where<ARTran.tranType, Equal<Current<ARInvoice.docType>>,
                                    And<ARTran.refNbr, Equal<Current<ARInvoice.refNbr>>>>>
                                .Select(Base, invoice.RefNbr, invoice.DocType))
                            {


                                SOLine line1 = PXSelect<
                                    SOLine,
                                    Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                                        And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
                                        And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>
                                    .Select(Base, tran1.SOOrderType, tran1.SOOrderNbr, tran1.SOOrderLineNbr);

                                if (line1 != null)
                                {

                                    SOLine line = new SOLine();


                                    line.InventoryID = line1.InventoryID;

                                    ItemAvailabilityExt.Check(line);

                                    //line.UOM = tran1.UOM;
                                    line.BranchID = line1.BranchID;
                                    line.OrderQty = line1.OrderQty;
                                  
                               Saleorderval(tran1,line1);     

                                    line.UOM = line1.UOM;
                                    line.InvoiceNbr = invoice.RefNbr;

                                    PXDBQuantityAttribute.CalcTranQty<SOLine.orderQty>(Base.Transactions.Cache, line1);

                                    Base.Transactions.Insert(line);

                                }


                              
                            }

                        }
                        catch (PXException ex)
                        {
                            //  throw ex.Message;
                        }

 

  public void  Saleorderval(ARTran tran, SOLine line2)
        {

            foreach (SOLine line
                 in PXSelect<SOLine, Where<SOLine.invoiceNbr, Equal<Required<SOLine.invoiceNbr>>, And<SOLine.inventoryID, Equal<Required<SOLine.inventoryID>>>>>.Select(Base, tran.RefNbr, tran.InventoryID))
            {

                if (line.OrderType == "RC")
                {
                    if (line.CustomerID == tran.CustomerID)
                    {
                        if (line.InvoiceNbr == tran.RefNbr)
                        {


                            if (tran.Qty != (LineQtyCount))
                            {
                                LineQtyCount = LineQtyCount + line.OrderQty;

                                if (line.OrderQty != LineQtyCount)
                                {
                                  

                                    //   throw new PXException(Messages.SOLine, PXErrorLevel.RowError);
                             PXUIFieldAttribute.SetError<SOLine.orderQty>(Base.Transactions.Cache, line1, "No");
                                }

                            }
                        }
                    }
                }

View original
Did this topic help you find an answer to your question?

7 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @Atiq,

You can override the method use the following to set the error on certain field,

PXUIFieldAttribute.SetError<SOLine.orderQty>(sender, e.Row, warning);

 Hope that helps.! If you need further information, feel free share more details on the requirements and current implementation.


Atiq
Jr Varsity III
Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 38 replies
  • October 18, 2023

Hi @Vignesh Ponnusamy ,

                                           

  public void saleorderval( ARTran tran, SOLine line2)
        {

           foreach (SOLine line
                in PXSelect<SOLine, Where<SOLine.invoiceNbr, Equal<Required<SOLine.invoiceNbr>>, And<SOLine.inventoryID, Equal<Required<SOLine.inventoryID>>>>>.Select(Base, tran.RefNbr, tran.InventoryID))
            {

                if (line.OrderType == "RC")
                {
                    if (line.CustomerID == tran.CustomerID)
                    {
                        if (line.InvoiceNbr == tran.RefNbr)
                        {
                            LineQtyCount = LineQtyCount + line.OrderQty;


                            if (line.OrderQty != (LineQtyCount))
                            {
                                
                                try
                                {
                                   
                                    PXUIFieldAttribute.SetError<SOLine.orderQty>(sender, e, "Yes");
                                }
                                catch(Exception ex)
                                {

                                }
                              

                            }
                        }
                    }
                }

 

i have created a methord and the method has no cache attached to it, in this case what parameters should be passed to SetError Method?


RohitRattan88
Acumatica Moderator
Forum|alt.badge.img+4
  • Acumatica Moderator
  • 253 replies
  • October 18, 2023

@Atiq In API reference guide, i dont see any method overload without PXCache;

 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @Atiq,

You can use the cache of the transaction and pass the current detail line of the loop, below is an example of action in SOOrderEntry that does set the error when the quantity is greater that 0.

    public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
    {
        #region Event Handlers
        public PXAction<SOOrder> setError;
        [PXUIField(DisplayName = "Set Error")]
        [PXButton]
        protected IEnumerable SetError(PXAdapter adapter)
        {
            foreach (SOLine line in Base.Transactions.Select())
            {
                if (line.OrderQty > 0)
                {
                    PXUIFieldAttribute.SetError<SOLine.orderQty>(Base.Transactions.Cache, line, "Yes");
                }
            }
            return adapter.Get();
        }
        #endregion
    }

Feel free to post if you have any questions, along graph extension as it might give us a better context of what you are trying to accomplish. Good Luck.!


Atiq
Jr Varsity III
Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 38 replies
  • October 18, 2023

Hi @Vignesh Ponnusamy ,

                                  Thank you for the Response, i have tried the above approch But it didnt work.        Actually, in my requirement,  For RC Sales Order i have added a button in SOline, which populates all the invoices for the current customer in a popup.  and when i select any invoice then it brings all the iventory items to soline which i have Achived. but there is another conditon which needs to be implemented i.e it should compare the items qty of the selected invoice items and sum of Qty of existing RC orders,  if it does not match the condition it should display an error.   For this Reason i have created a method that pulls soline and tran values and i call it from Action,  But iam not able to implement the Error . 

“The return quantity exceeds the quantity available for return for the related invoice line AR010261, FOODCHIP36. Decrease the quantity in the current line, or in the corresponding line of another return document or documents AR010308, AR010316 that exist for the invoice line.”


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @Atiq,

Can you please share a simplified customization project using which we could reproduce the issue?


Atiq
Jr Varsity III
Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 38 replies
  • Answer
  • October 23, 2023

Hi Vignesh,  

i have written the logic to bring the soline values from artran,  and using Saleorderval(tran1,line1); method,  iam populating the error

 public virtual IEnumerable invFilter(PXAdapter adapter)
        {

            var x = AlternateInvId.Select().Count;
            var q = Invview.Select().Count;
            var s = Lineqty.Select().Count;


            var k = Invview.AskExt();
            if (this.Invview.AskExt() == WebDialogResult.OK)
            {
                foreach (ARInvoice invoice in Invview.Select())

                {
                    if (invoice.Selected == true)
                    {

                        try
                        {
                            foreach (SOLine sO in Lineqty.Select())
                            {
                                var kb = sO.InvoiceNbr;
                                var aa = sO.OrderNbr;
                            }

                            foreach (ARTran tran1 in PXSelect<
                                ARTran,
                                Where<ARTran.tranType, Equal<Current<ARInvoice.docType>>,
                                    And<ARTran.refNbr, Equal<Current<ARInvoice.refNbr>>>>>
                                .Select(Base, invoice.RefNbr, invoice.DocType))
                            {


                                SOLine line1 = PXSelect<
                                    SOLine,
                                    Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                                        And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
                                        And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>
                                    .Select(Base, tran1.SOOrderType, tran1.SOOrderNbr, tran1.SOOrderLineNbr);

                                if (line1 != null)
                                {

                                    SOLine line = new SOLine();


                                    line.InventoryID = line1.InventoryID;

                                    ItemAvailabilityExt.Check(line);

                                    //line.UOM = tran1.UOM;
                                    line.BranchID = line1.BranchID;
                                    line.OrderQty = line1.OrderQty;
                                  
                               Saleorderval(tran1,line1);     

                                    line.UOM = line1.UOM;
                                    line.InvoiceNbr = invoice.RefNbr;

                                    PXDBQuantityAttribute.CalcTranQty<SOLine.orderQty>(Base.Transactions.Cache, line1);

                                    Base.Transactions.Insert(line);

                                }


                              
                            }

                        }
                        catch (PXException ex)
                        {
                            //  throw ex.Message;
                        }

 

  public void  Saleorderval(ARTran tran, SOLine line2)
        {

            foreach (SOLine line
                 in PXSelect<SOLine, Where<SOLine.invoiceNbr, Equal<Required<SOLine.invoiceNbr>>, And<SOLine.inventoryID, Equal<Required<SOLine.inventoryID>>>>>.Select(Base, tran.RefNbr, tran.InventoryID))
            {

                if (line.OrderType == "RC")
                {
                    if (line.CustomerID == tran.CustomerID)
                    {
                        if (line.InvoiceNbr == tran.RefNbr)
                        {


                            if (tran.Qty != (LineQtyCount))
                            {
                                LineQtyCount = LineQtyCount + line.OrderQty;

                                if (line.OrderQty != LineQtyCount)
                                {
                                  

                                    //   throw new PXException(Messages.SOLine, PXErrorLevel.RowError);
                             PXUIFieldAttribute.SetError<SOLine.orderQty>(Base.Transactions.Cache, line1, "No");
                                }

                            }
                        }
                    }
                }


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings