1
votes

I have a custom graph, in this case called MyGraph. The page contains a Form Tab in a similar fashion to the Stocked Items page in which the header is a few fields of my DAC (MyDAC), and a form on the 1st tab is a form of my additional fields. The views, for the sake of discussion, are MyView and MyCurrentView.

On the Stocked Items page, I can set a value in the ItemSettings view (General Settings tab) and then execute an action which also happens to save my user input. In my custom page, the user input of the similar "MyCurrentView" tab is lost when I execute an action. I have reviewed the training material once again for T230 Actions, but I cannot seem to overcome this problem. The code sample below shows 2 simplified methods of how I execute the action "ConvertIt". In both cases during a Debug, both myDAC and myDAC2 contain the stale data, indicating that the view was not updated as expected per CommitChanges in the Button attribute and in the DataSource Callback Command. The user input that is not saved is entered via a field presented to the UI only in MyCurrentView.

The T230 training guide indicates that I should set the AutoCallBack Behavior in the action bar, which appears to be possible for a grid, but not for a form. The example from the training guide is:

<ActionBar>
    <CustomItems>
        <px:PXToolBarButton Text="Complete">
            <AutoCallBack Command="Complete" Target="ds">
                <Behavior CommitChanges="True" ></Behavior>
            </AutoCallBack>
        </px:PXToolBarButton>
    </CustomItems>
</ActionBar>

Since I am hanging my action off the Action menu via action.AddMenuAction(convertIt);, I do not seem to have a way to specify the behavior as described in the training guide.

Views Defined

public PXSelect<MyDAC> MyView;
public PXSelect<MyDAC, Where<MyDAC.tagID, Equal<Current<MyDAC.tagID>>>> MyCurrentView;

Action Defined - Method 1

#region convertIt Action
public PXAction<MyDAC> convertIt;
[PXUIField(DisplayName = "My DAC Label", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
[PXButton(CommitChanges = true)]
public virtual void ConvertIt()
{

    this.Save.Press();   // Seems to make no difference in saving the unsaved user entry

    MyDAC myDAC = MyView.Current;
    MyDAC myDAC2 = MyCurrentView.Current;

    ** DO THE WORK OF THE ACTION HERE **

}
#endregion

Action Defined - Method 2

#region convertIt Action
public PXAction<MyDAC> convertIt;
[PXUIField(DisplayName = "My DAC Label", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
[PXButton(CommitChanges = true)]
public virtual IEnumerable ConvertIt(PXAdapter adapter)
{

    MyDAC myDAC = MyView.Current;
    MyDAC myDAC2 = MyCurrentView.Current;

    ** DO THE WORK OF THE ACTION HERE **

    return adapter.Get();
}
#endregion

ASPX Datasource Defined

<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%"
    TypeName="MyGraph"
    PrimaryView="MyView">
    <CallbackCommands>
        <px:PXDSCallbackCommand CommitChanges="True" Name="ConvertIt" ></px:PXDSCallbackCommand>
    </CallbackCommands>
</px:PXDataSource>

In short, user input is lost when I complete my action. I have tried including this.Save.Press() at the beginning of my action, but I already save at the end of my action. Regardless, a Debug does not show my user entered values in the view, although I expected the commit changes on the button and in the data source to commit those changes from the client before proceeding with the action.

What have I left out of the C# code or ASPX page definition that is preventing my UI updates to be applied? Interestingly enough, UI changes in the MyView view ARE applied, but not changes in MyCurrentView unless I literally press the save button manually before selecting the action from the menu.

2

2 Answers

1
votes

I ran into this problem recently as well. It’s easy to force the page to post back to server when opening a smart panel off of an action, but if there is no panel opening how do you force a post of data that was changed in fields that don’t commit on update? The only way I’ve found to accomplish this is by editing the ASPX and adding StartNewGroup="true" and CommitChanges="true" to the PXDSCallbackCommand for the Action Folder that the action is added to.

<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%"
    TypeName="MyGraph"
    PrimaryView="MyView">
    <CallbackCommands>
        <px:PXDSCallbackCommand CommitChanges="True" Name="ActionFolder" StartNewGroup="True" />
    </CallbackCommands>
</px:PXDataSource>

For the action, you should use the second method.

public PXAction<MyDAC> convertIt;
[PXUIField(DisplayName = "My DAC Label", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
[PXButton(CommitChanges = true)]
public virtual IEnumerable ConvertIt(PXAdapter adapter)
{
    MyDAC myDAC = MyView.Current;
    MyDAC myDAC2 = MyCurrentView.Current;

    **DO THE WORK OF THE ACTION HERE **
        
    return adapter.Get();
}

public MyGraph()
{
    actionFolder.AddMenuAction(convertIt);
}

0
votes

It is not possible to save the focused field value. Value is saved when the control lose focus. However when the focus goes from an uncommitted field to an action button (clicked by user) the current field value is lost. Not sure this is the issue here but keep in mind that the user has to tab out of a control editor with uncommitted value before clicking on an action button or else the value is lost.