Skip to main content

Hi, 

I have a newly created screen including a form and grid. I have modified a button to pop-up a window which consists data of POOrder and POLine tables. To load data from these two tables, I have defined a view like below.

public SelectFrom<POLine>
          .InnerJoin<POOrder>.On<POLine.orderNbr.IsEqual<POOrder.orderNbr>  
          .And<POLine.orderType.IsEqual<POOrder.orderType>>>
          .View POrdersView;

I want to add some values from this smart panel to my custom grid in the screen. After adding the values to the grid, when I try to save to the database, I’m getting below error.

 

There is no field called ‘OrderDate’ in my DAC for the grid, but both POOrder and POline have ‘OrderDate’. Even I don’t try to update records in these two tables, How can I get this error? Does someone have an idea on how to solve this?

thank you

If you are only using the POOrder and POLine as references for data to view only, try using SelectFrom<>.View.ReadOnly to define your view. That should not allow any record updates at all to happen, so if something behind the scenes is changing the order date, it shouldn’t be able to if the view is defined like that.


Hi @oshadarodrigo64  Can you please share the source code (DAC and Graph files), so that we can review and help you if we can found something strange?


Hi @Naveen Boga ,

Ok , I will share with you .


Hi ,

I have defined the view like this now.

public PXSelectReadonly2<POLine,
          InnerJoin<POOrder,On<POLine.orderNbr,Equal<POOrder.orderNbr>,
          And<POLine.orderType, Equal<POOrder.orderType>>>>, Where<POLine.vendorID, Equal<Current<APProforma.customerID>>>>
          POrdersView;

 

After defining the view like above, I’m not able to select one by one, but when I click add-close button all the values are added and can be saved without getting the ‘OrderDate cannot be empty error’. 

as you can see that the selected row is not checked

I think this is happening because of using the PXselectReadonly attribute as it creates a read-only view . I have taken the selected feild from POLine dac to allow user to select the value. So how Can I enable editable only to the one feild (selected) to allow check it.? below I mentioned a method that I have attempted but it didn’t work as it is.

protected virtual void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
        {
            PXUIFieldAttribute.SetReadOnly<POLine.selected>(cache, e.Row, false);
            PXUIFieldAttribute.SetEnabled<POLine.selected>(cache, e.Row, true);

        }


I did not picture that’s how you are using it. You won’t be able to use the read only for that case. 

What is the logic you are using when adding the selected items from the smart panel to the grid? 


Hi @epetruncio89 ,

for the smart panel I need to load data from both POLine and POOrder. for that I have defined the view using PXSelectReadonly2 attribute to avoid ‘OrderDate cannot be empty error’. now the error is gone when saving the added data in the grid to the database. but my issue is I cannot select and add one by one from smart panel because i’m not allowed to select the check box there. Instead of that, when I select add button in the smart panel, all the available values are added to the grid. To allow user to select one value, I have added the field ‘selected’ of POLine. so I thought that I’m getting this issue because I have a read-only view, so I thought of trying to change only the specific field ‘selected’ to set editable, but I don’t know whether it is correct or wrong, However I have put the whole code of the graph for your reference. 


namespace GRIProformaInvoice.Extension
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class APProformaEntry_Extension : PXGraphExtension<APProformaEntry>
{

public PXSelectReadonly2<POLine,
InnerJoin<POOrder,On<POLine.orderNbr,Equal<POOrder.orderNbr>,
And<POLine.orderType, Equal<POOrder.orderType>>>>, Where<POLine.vendorID, Equal<Current<APProforma.customerID>>>>
POrdersView;

public PXAction<APProforma> MyAction;
MPXUIField(DisplayName = "Add Purchase", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
.PXButton(CommitChanges = true)]
public virtual IEnumerable myAction(PXAdapter adapter)
{
try
{
if (POrdersView.AskExt() == WebDialogResult.OK)
{
return InsertSelectedLines(adapter);
}
}

catch (PXDialogRequiredException ex)
{
PXTrace.WriteError(ex);

throw;
}
return adapter.Get();
}

public virtual IEnumerable InsertSelectedLines(PXAdapter adapter)
{
if (POrdersView != null)
{
int lineNbr = Base.APProformaItems.Select().Count + 1;
foreach (PXResult< POLine, POOrder> result in POrdersView.Select())
{
POOrder order = result;
POLine line = result;

if (line.Selected == false) continue;

{
APProformaItemList toBeInserted = new APProformaItemList();
toBeInserted.Ponbr = order.OrderNbr;
toBeInserted.LineNbr = lineNbr++;
toBeInserted.POLineNbr = line.LineNbr;
toBeInserted.POrderQty = 30;
toBeInserted.Itemid = 25;
toBeInserted.Description = line?.TranDesc;
toBeInserted.Amount = line.ExtCost;
toBeInserted = Base.APProformaItems.Insert(toBeInserted);
Base.APProformaItems.Update(toBeInserted);

}
}

}
return adapter.Get();

}


protected virtual void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
PXUIFieldAttribute.SetReadOnly<POLine.selected>(cache, e.Row, false);
PXUIFieldAttribute.SetEnabled<POLine.selected>(cache, e.Row, true);

}

If you could find something strange in this code , it will be helpful if you can let me know,

thank you.


I changed the view like this now,

public PXSelectJoin<POLine,

          InnerJoin<POOrder, On<POLine.orderNbr, Equal<POOrder.orderNbr>,

          And<POLine.orderType, Equal<POOrder.orderType>>>>, Where<POLine.vendorID, Equal<Current<APProforma.customerID>>>>

          POrdersView;

but this time I’m getting the same error - ‘OrderDate cannot be empty’ again when saving to the database, attempted many approaches but still couldn’t find the solution.


You should remove the PXReadOnly and replace it with your original code you had in place. I did not realize you were using that smart panel to select lines to add like that. You won’t be able to do it with the view defined using PXReadOnly. I strongly advise you revert to your original code. I am looking into the code you provided now.


I’m looking into the code and I cannot find the view “APProformaItems.” I am trying to find that to see what DAC it references. My suspects are that those DAC items might contain a field labeled “Order Date” that might be required to be populated. My suggestion would be to see if there is a date, and if so, populate it using the order date from the purchase order.

 

If that isn’t the case, can you provide where I can find the APProformaItems view?


Hi @epetruncio89,

please check the PM.


Hi,

I have done below modifications for the code that I have provided for the last time.
 

changed the view definition like this:

public PXSelectJoin<POLine,
          InnerJoin<POOrder, On<POLine.orderNbr, Equal<POOrder.orderNbr>,
          And<POLine.orderType, Equal<POOrder.orderType>>>>, Where<POLine.vendorID, Equal<Current<APProforma.customerID>>>>
          POrdersView;

 

changed the row_selected event like this:

protected virtual void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
        {
           PXUIFieldAttribute.SetEnabled(cache, e.Row, false);
           PXUIFieldAttribute.SetEnabled<POLine.selected>(cache, e.Row, true);  //to enable editable specific field ‘selected’ of POLine 
            
        }

 

I can add selected data to the grid but when I try to save it to the database, I’m still getting the error

“‘OrderDate’ cannot be empty”, Does someone have an idea on how to resolve this?


Can you provide a trace log with the stack trace?


Hi all, I solved this issue.

I added below snippet to clear cache at the end of InsertSelectedLines method in the graph extension and the error is gone.

POrdersView.Cache.Clear();
POrdersView.View.Clear();
POrdersView.Cache.ClearQueryCache();

Thank you all and highly appreciate your support on this .

Regards.


Thank you for sharing your solution with the community @oshadarodrigo64 !


Reply