Skip to main content
Solved

Error: The record cannot be saved.

  • August 26, 2022
  • 4 replies
  • 705 views

Forum|alt.badge.img+7

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?

Best answer by Django

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

 

4 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • August 27, 2022

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.


Forum|alt.badge.img+7
  • Author
  • Captain II
  • August 30, 2022

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.


Forum|alt.badge.img+7
  • Author
  • Captain II
  • Answer
  • August 30, 2022

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

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • August 30, 2022

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