Solved

Error: The record cannot be saved.

  • 27 August 2022
  • 4 replies
  • 369 views

Userlevel 7
Badge +5

I’m puzzled over this - hopefully it’s something silly that I’m missing.

I have an Action button on SOOrderEntry.  The goal is to look through the detail lines on the order, create a record in another graph, update some fields on SOLine and save the order.

Each time I call Actions.PressSave from within the CreateJobs method I get the error “The record cannot be saved.” I thought I was doing something wrong so I stripped out all of the code. I’ve tried it on two different Acumatica installations.

public static bool IsActive()
{
return true;
}

public PXAction<SOOrder> TestAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Test", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = true)]
protected virtual IEnumerable testAction(PXAdapter adapter)
{
Base.Actions.PressSave();
var graphCopy = Base;
PXLongOperation.StartOperation(graphCopy, delegate () { CreateJobs(graphCopy); });
return adapter.Get();
}

private static void CreateJobs(SOOrderEntry soOrderEntry)
{
soOrderEntry.Actions.PressSave();
return;
}

As you can see - I’ve stripped down the code to doing nothing at all.

So there must be something that I’m not understanding or missing. I feel like this is right out of T230 - what am I missing?

icon

Best answer by Django 30 August 2022, 21:12

View original

4 replies

Userlevel 7
Badge +17

Hi, @ddunn  Below is the reason for getting this issue.

In Acumatica, when the document is in shipping, completed, or cancelled statuses, the document will go to the read-only mode (the system will not allow us to edit the fields), but, when we are trying to edit this through code level we will get this issue.

Userlevel 7
Badge +5

So, as a test, I tried this:

public static bool IsActive()
{
return true;
}

public PXAction<SOOrder> TestAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Test", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = true)]
protected virtual IEnumerable testAction(PXAdapter adapter)
{
Base.Actions.PressSave();
PXLongOperation.WaitCompletion(Base.UID);


Base.Actions.PressSave();//ADDED THIS LINE

var graphCopy = Base;

graphCopy.Actions.PressSave(); //ADDED THIS LINE

PXLongOperation.StartOperation(graphCopy, delegate () { CreateJobs(graphCopy); });

return adapter.Get();
}

private static void CreateJobs(SOOrderEntry soOrderEntry)
{
soOrderEntry.Actions.PressSave();
return;
}

The second call to Base.Actions.PressSave() does not cause an error. 

The call to graphCopy.Actions.PressSave() does not cause an error.

The call to soOrderEntry.Actions.PressSave() does cause the error.

It does happen to be wrapped within the PXLongOperation.

So, as a further test I removed the PXLongOperation:

      Base.Actions.PressSave();
PXLongOperation.WaitCompletion(Base.UID);

Base.Actions.PressSave();
var graphCopy = Base;

graphCopy.Actions.PressSave();

CreateJobs(graphCopy);

return adapter.Get();

And no errors.

So the issue happens within the PXLongOperation only.

I’m still not sure where the issue is - I want to be able to run my code within the PXLongOperation.

Userlevel 7
Badge +5

Okay - I came across this from Yuriy’s blog (https://blog.zaletskyy.com/post/2020/06/11/post100). This pattern seems to work just fine.

{

Base.Actions.PressSave();

var doc = Base.Document.Current;
var orderType = doc.OrderType;
var orderNbr = doc.OrderNbr;

PXLongOperation.WaitCompletion(Base.UID);
myTrace("Before second Save");
Base.Actions.PressSave();

myTrace("Before third Save");
graphCopy.Actions.PressSave();
PXLongOperation.StartOperation(Base, ()=> {

var grp = PXGraph.CreateInstance<SOOrderEntry>();
grp.Document.Current = grp.Document.Search<SOOrder.orderNbr>(orderNbr, orderType);

grp.Save.Press(); //Doesn't generate errors


CreateJobs(grp);

});
}

private static void CreateJobs(SOOrderEntry soOrderEntry)
{

myTrace("Before CreateJobs Save");
soOrderEntry.Actions.PressSave(); //NO LONGER GENERATES AN ERROR
myTrace("After CreateJobs Save.");
return;

} //CreateJobs

 

Userlevel 7
Badge

Thank your for sharing your resolution with the community @ddunn !

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved