I'm trying to add a next/previous button on the CashAccountDetails page (CATranEnq Graph).
This is what I tried this far:
using PX.Data;
using PX.Objects.GL;
using System.Linq;
namespace PX.Objects.CA
{
public class CATranEnqExtension : PXGraphExtension<CATranEnq>
{
private class ActionsLabels
{
public const string NextAccount = "Compte suivant";
public const string PreviousAccount = "Compte précédent";
}
public PXAction<CAEnqFilter> PreviousAccount;
[PXUIField(DisplayName = ActionsLabels.PreviousAccount, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXPreviousButton]
public virtual void previousAccount()
{
CAEnqFilter filter = Base.Filter.Current;
Account previousaccount = new Account();
if (!filter.AccountID.Equals(null))
{
Account currentAccount = PXSelect<Account, Where<Account.accountID,
Equal<Required<Account.accountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
previousaccount = PXSelect<Account,
Where<Account.accountCD,
Less<Required<Account.accountCD>>,
And<Account.isCashAccount, Equal<True>>>,
OrderBy<Desc<Account.accountCD>>>.Select(Base, currentAccount.AccountCD).FirstOrDefault();
}
else
{
previousaccount = PXSelect<Account,
Where<Account.isCashAccount, Equal<True>>,
OrderBy<Desc<Account.accountCD>>>.Select(Base).FirstOrDefault();
}
filter.AccountID = previousaccount?.AccountID;
}
public PXAction<CAEnqFilter> NextAccount;
[PXUIField(DisplayName = ActionsLabels.NextAccount, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXNextButton]
public virtual void nextAccount()
{
CAEnqFilter filter = Base.Filter.Current;
Account nextaccount = new Account();
if (!filter.AccountID.Equals(null))
{
Account currentAccount = PXSelect<Account, Where<Account.accountID,
Equal<Required<Account.accountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
nextaccount = PXSelect<Account,
Where<Account.accountCD,
Greater<Required<Account.accountCD>>,
And<Account.isCashAccount, Equal<True>>>,
OrderBy<Asc<Account.accountCD>>>.Select(Base, currentAccount.AccountCD).FirstOrDefault();
}
else
{
nextaccount = PXSelect<Account,
Where<Account.isCashAccount, Equal<True>>,
OrderBy<Asc<Account.accountCD>>>.Select(Base).FirstOrDefault();
}
filter.AccountID = nextaccount?.AccountID;
}
}
}
When I click on the buttons I expect to go to another CashAccount, but instead the AccountID gets used and it doesnt find the account :
https://i.imgur.com/Uo7MCWL.png
I had to use a CashAccount object and not an account.
CAEnqFilter filter = Base.Filter.Current;
CashAccount previousaccount = new CashAccount();
if (!filter.AccountID.Equals(null))
{
CashAccount currentAccount = PXSelect<CashAccount, Where<CashAccount.cashAccountID,
Equal<Required<CashAccount.cashAccountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
previousaccount = PXSelect<CashAccount,
Where<CashAccount.cashAccountCD,
Less<Required<CashAccount.cashAccountCD>>>,
OrderBy<Desc<CashAccount.cashAccountCD>>>.Select(Base, currentAccount.CashAccountCD).FirstOrDefault();
}
else
{
previousaccount = PXSelectOrderBy<CashAccount,
OrderBy<Desc<CashAccount.cashAccountCD>>>.Select(Base).FirstOrDefault();
}
filter.AccountID = previousaccount?.CashAccountID;
Related
I am looking for help, I hope I can solve this problem.
I've created a new screen and I'm filtering all the Revalue Accounts information.
With this screen, what I want to do is insert and at the same time add an additional new line within the grid.
Here is my new created screen and the button that inserts GLTran
I am attaching an image where I want the line to be added at insert time
Here I share code that I have and it does not work for the additional line.
private void CreateDNGL(Batch batch)
{
var graph = PXGraph.CreateInstance<JournalEntry>();
if (graph.BatchModule.Current == null)
{
Batch cmbatch = new Batch();
cmbatch.BranchID = batch.BranchID;
cmbatch.Module = batch.Module;
cmbatch.Status = "U";
cmbatch.AutoReverse = true;
cmbatch.Released = true;
cmbatch.Hold = false;
cmbatch.CuryDebitTotal = batch.CuryDebitTotal;
cmbatch.CuryCreditTotal = batch.CuryCreditTotal;
cmbatch.FinPeriodID = batch.FinPeriodID;
cmbatch.CuryID = batch.CuryID;
cmbatch.CuryInfoID = batch.CuryInfoID;
cmbatch.DebitTotal = batch.DebitTotal;
cmbatch.CreditTotal = batch.CreditTotal;
cmbatch.Description = "Head new insert";
cmbatch = graph.BatchModule.Insert(cmbatch);
}
foreach (GLTran item in PXSelect<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(this, batch.Module, batch.BatchNbr))
{
GLTran tran = new GLTran();
tran.SummPost = item.SummPost;
tran.ZeroPost = false;
tran.DebitAmt = item.DebitAmt;
tran.CreditAmt = item.CreditAmt;
tran.CuryDebitAmt = item.CuryDebitAmt;
tran.CuryCreditAmt = item.CuryCreditAmt;
tran.AccountID = item.AccountID;
tran.SubID = item.SubID;
tran.LineNbr = item.LineNbr;
tran.LedgerID = item.LedgerID;
tran.TranType = item.TranType;
tran.TranClass = item.TranClass;
tran.RefNbr = string.Empty;
tran.FinPeriodID = item.FinPeriodID;
tran.TranDesc = "Test detail";
tran.Released = true;
tran.ReferenceID = item.ReferenceID;
tran = graph.GLTranModuleBatNbr.Insert(tran);
Account account = PXSelect<Account, Where<Account.accountID,
Equal<Required<Account.accountID>>>>.Select(graph, item.AccountID);
xLocEquivalAcct equivalAcct = PXSelect<xLocEquivalAcct, Where<xLocEquivalAcct.acctCD,
Equal<Required<xLocEquivalAcct.acctCD>>>>.Select(graph, account.AccountCD);
if (equivalAcct != null)
{
/*here is added for an additional line*/
var glTran = graph.GLTranModuleBatNbr.Insert();
graph.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, 343567);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, 281);
glTran.TranDesc = "add extra line";
if (item.DebitAmt != 0m && item.CreditAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyDebitAmt>(glTran, item.CuryDebitAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.debitAmt>(glTran, item.DebitAmt);
}
}
if (item.CreditAmt != 0m && item.DebitAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyCreditAmt>(glTran, item.CuryCreditAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.creditAmt>(glTran, item.CreditAmt);
}
}
glTran = graph.GLTranModuleBatNbr.Update(glTran);
}
}
graph.Save.Press();
}
I hope I was clear with my question.
This code will create a copy of the originating batch and insert additional lines.
#Warning Your original code was attempting to create a batch that was already released but unposted. I can update my answer to match your requirement but this will break Acumatica work-flow.
Please find code example below :
public class JournalEntryExtension : PXGraphExtension<JournalEntry>
{
public PXAction<Batch> CopyCreate;
//CommitChanges being set to false allows the graph to not be considered dirty when there are errors that we manually show on screen. Case #207998
[PXButton(CommitChanges = false)]
[PXUIField(DisplayName = "Copy Create", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true)]
protected virtual IEnumerable copyCreate(PXAdapter pxAdapter)
{
if (Base.BatchModule.Current != null)
{
if (Base.IsDirty)
{
Base.BatchModule.Ask("You must discard your unsaved changes to be able to press this button.", MessageButtons.OK);
}
else
{
Batch batch = Base.BatchModule.Current;
PXLongOperation.StartOperation(this, () => CreateDNGL(batch));
}
}
return pxAdapter.Get();
}
private static void CreateDNGL(Batch batch)
{
JournalEntry graph = PXGraph.CreateInstance<JournalEntry>();
Batch newBatch = PXCache<Batch>.CreateCopy(batch);
newBatch.NoteID = null;
newBatch.Description = "Test header";
newBatch = graph.BatchModule.Insert(newBatch);
GLTran newTran;
foreach (GLTran tran in PXSelectReadonly<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(graph, batch.Module, batch.BatchNbr))
{
newTran = PXCache<GLTran>.CreateCopy(tran);
newTran.Module = null;
newTran.BatchNbr = null;
newTran.NoteID = null;
newTran.TranDesc = "Test detail";
newTran = graph.GLTranModuleBatNbr.Insert(newTran);
}
if (true)
{
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryDebitAmt = 1000;
newTran.TranDesc = "Additional Line 1";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryCreditAmt = 1000;
newTran.TranDesc = "Additional Line 2";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
}
graph.Save.Press();
}
}
Original Batch :
New Batch :
I have created a Action called "CREATE SO" in Sales Quote(CR304500) screen to create Sales Order. I have created a ComboBox udf "Sales Order Type" to select "Doc Type" of the Sales Order to be created.
When I am selecting DocType as "SO", its giving error "Unit
Conversion is missing". (see pic)
When I am selecting any other DocType it gives an error "RevisionID
cannot be empty".(see pic)
"SO" is the default Order Type in SO Preferences. I am unable to track the error using debugger. Please suggest. Thanks. Following is my code.
#region Create Sales Order
public PXAction<CRQuote> createSalesOrder;
[PXUIField(DisplayName = "Create SO", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton(CommitChanges = true)]
public IEnumerable CreateSalesOrder(PXAdapter adapter)
{
QuoteMaint graphObject = PXGraph.CreateInstance<QuoteMaint>();
foreach (CRQuote quote in adapter.Get())
{
//Create resultset for Quote Details
PXResultset<CROpportunityProducts> PXSetLine = PXSelect<CROpportunityProducts,
Where<CROpportunityProducts.quoteID,
Equal<Required<CROpportunityProducts.quoteID>>>>.Select(this.Base, quote.QuoteID);
List<CROpportunityProducts> QuoteList = new List<CROpportunityProducts>();
foreach (CROpportunityProducts line in PXSetLine)
{
QuoteList.Add(line);
}
bool var_orderCreated = false;
bool erroroccured = false;
string ErrMsg = "";
SOOrderEntry orderGraphObjet = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder orderHeaderObject = new SOOrder();
QuoteMaint currGRPH = PXGraph.CreateInstance<QuoteMaint>();
CRQuoteExt _quoteExt = PXCache<CRQuote>.GetExtension<CRQuoteExt>(quote);
var Extension = this.Base.GetExtension<QuoteMaint_Extension>();
orderHeaderObject = orderGraphObjet.CurrentDocument.Insert(orderHeaderObject);
BAccount customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<CRQuote.bAccountID>>>>.Select(this.Base, quote.BAccountID);
if (customer.Type == "CU")
{
orderHeaderObject.CustomerID = quote.BAccountID;
orderHeaderObject.CustomerLocationID = quote.LocationID;
}
else
{
throw new PXException("Business Account not converted to Customer yet");
}
if (quote.CuryProductsAmount != 0)
{
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
}
else
{
throw new PXException("Total cannot be 0");
}
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
orderHeaderObject.CuryTaxTotal = quote.CuryTaxTotal;
orderHeaderObject.OrderDesc = quote.Subject;
orderHeaderObject.OrderType = _quoteExt.UsrOrderNbr;
orderGraphObjet.Document.Update(orderHeaderObject);
orderGraphObjet.CurrentDocument.Current = orderHeaderObject;
orderGraphObjet.Actions.PressSave();
orderHeaderObject = orderGraphObjet.CurrentDocument.Current;
foreach (CROpportunityProducts tran in QuoteList)
{
SOLine transline = new SOLine();
orderGraphObjet.Transactions.Insert(transline);
transline.OrderNbr = orderHeaderObject.OrderNbr;
transline.BranchID = orderHeaderObject.BranchID;
transline.InventoryID = tran.InventoryID;
transline.TranDesc = tran.Descr;
transline.UOM = tran.UOM;
transline.OrderQty = tran.Quantity;
transline.SiteID = tran.SiteID;
transline.CuryUnitPrice = tran.CuryUnitPrice;
transline.CuryExtPrice = tran.CuryExtPrice;
transline.CuryLineAmt = tran.CuryAmount;
CROpportunityProductsExt xOppProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt>(tran);
SOLineExt _soLext = PXCache<SOLine>.GetExtension<SOLineExt>(transline);
_soLext.UsrXSeqID = xOppProductExt.UsrXSequenceID;
_soLext.UsrXGroupID = xOppProductExt.UsrXGroupID;
_soLext.UsrInternalRemk = xOppProductExt.UsrInternalRemk;
orderGraphObjet.Transactions.Update(transline);
}
orderGraphObjet.Actions.PressSave(); //This is the line where both the error is showing
if (orderGraphObjet != null && orderHeaderObject != null)
{
orderGraphObjet.Document.Current = orderHeaderObject;
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
yield return quote;
}
}
############## DAC FIELD #####################
[PXDBString(50)]
[PXUIField(DisplayName = "Sales Order Type")]
[PXDefault()]
[PXStringList(new string[] { "SO", "SP", "SS" }, new string[] { "SO - Sales Order", "SP - Sales Of Project", "SS - Sales Of Service" })]
public virtual string UsrOrderNbr { get; set; }
public abstract class usrOrderNbr : PX.Data.BQL.BqlString.Field<usrOrderNbr> { }
I would suggest that when you insert your new objects into the cache, that you insert an object with it's key elements already entered. For instance, I would add CustomerID and CustomerLocationID to orderHeaderObject and then Insert it into the Document cache. When you do that, the Acumatica validation will fire and all the defaults will be set in your document before you try and edit them. Same goes for your line level object, I think that's the reason you're getting both errors. Also, I notice you trying to set the value for a few calculated fields. If possible I would try and leave these to calculate as designed.
I have created a Action called CREATE SO in Sales Quote screen to create Sales order.
I am unable to open the sales order screen using this action. though the sales order is getting created
but the SO screen is not opening while creating the SO. I am not sure where i am making mistake in my code. Please suggest. Thanks.
#region Create Sales Order
public PXAction<CRQuote> createSalesOrder;
[PXUIField(DisplayName = "Create SO", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton(CommitChanges = true)]
public IEnumerable CreateSalesOrder(PXAdapter adapter)
{
QuoteMaint graphObject = PXGraph.CreateInstance<QuoteMaint>();
foreach (CRQuote quote in adapter.Get())
{
//Create resultset for Quote Details
PXResultset<CROpportunityProducts> PXSetLine = PXSelect<CROpportunityProducts,
Where<CROpportunityProducts.quoteID,
Equal<Required<CROpportunityProducts.quoteID>>>>.Select(this.Base, quote.QuoteID);
List<CROpportunityProducts> QuoteList = new List<CROpportunityProducts>();
foreach (CROpportunityProducts line in PXSetLine)
{
QuoteList.Add(line);
}
PXLongOperation.StartOperation(this, () => CreateSalesOrderMethod(quote, QuoteList));
yield return quote;
}
}
//Private Method for Create Sales Order
public virtual void CreateSalesOrderMethod(CRQuote quote, List<CROpportunityProducts> QuoteList)
{
//Base.Save.Press();
bool var_orderCreated = false;
bool erroroccured = false;
string ErrMsg = "";
SOOrderEntry orderGraphObjet = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder orderHeaderObject = new SOOrder();
QuoteMaint currGRPH = PXGraph.CreateInstance<QuoteMaint>();
BAccount customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<CRQuote.bAccountID>>>>.Select(this.Base, quote.BAccountID);
if (customer.Type == "CU")
{
orderHeaderObject.CustomerID = quote.BAccountID;
}
else
{
throw new PXException("Business Account not converted to Customer yet"); // THIS ERROR IS ALSO NOT SHOWING WHILE ENCOUNTERING.
}
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
orderHeaderObject.CuryTaxTotal = quote.CuryTaxTotal;
orderHeaderObject.OrderDesc = quote.Subject;
orderHeaderObject = orderGraphObjet.CurrentDocument.Insert(orderHeaderObject);
orderGraphObjet.CurrentDocument.Current = orderHeaderObject;
orderGraphObjet.Actions.PressSave();
orderHeaderObject = orderGraphObjet.CurrentDocument.Current;
foreach (CROpportunityProducts tran in QuoteList)
{
SOLine transline = new SOLine(); //EMPTY DAC OBJECT
transline.OrderNbr = orderHeaderObject.OrderNbr;
transline.BranchID = orderHeaderObject.BranchID;
transline.InventoryID = tran.InventoryID;
transline.TranDesc = tran.Descr;
transline.UOM = tran.UOM;
transline.OrderQty = tran.Quantity;
transline.SiteID = tran.SiteID;
transline.CuryUnitPrice = tran.CuryUnitPrice;
transline.CuryExtPrice = tran.CuryExtPrice;
orderGraphObjet.Transactions.Insert(transline); //INSERT DAC INTO DATAVIEW
CROpportunityProductsExt xOppProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt>(tran);
SOLineExt _soLext = PXCache<SOLine>.GetExtension<SOLineExt>(transline); // GET DAC ENTENSION
_soLext.UsrXSeqID = xOppProductExt.UsrXSequenceID;
_soLext.UsrXGroupID = xOppProductExt.UsrXGroupID;
_soLext.UsrInternalRemk = xOppProductExt.UsrInternalRemk; // ASSIGN CUSTOM FIELDS
orderGraphObjet.Transactions.Update(transline); // UPDATE DAC OBJECT IN DATAVIEW
}
orderGraphObjet.Actions.PressSave();
var_orderCreated = true;
//if (orderGraphObjet != null && orderHeaderObject != null)
if (var_orderCreated)
{
orderGraphObjet.Document.Current = orderHeaderObject; // HERE I AM GETTING THE OrderType as well as OrderNbr to open the Document.
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
}
#endregion
}
}
The issue is that the redirection is in the PXLongOperation. A PXLongOperation starts a separate thread that is not related with the UI. In order to solve this you can use the PXCustomInfo structure to talk back with the UI thread after the long operation finishes and thus be able to redirect to the so screen.
// PXCustomInfoDefinition
public sealed class SORedirectionCustomInfo: IPXCustomInfo
{
private PXGraph _OrderGraph;
public SORedirectionCustomInfo(PXGraph orderGraph)
{
_OrderGraph = orderGraph;
}
public void Complete(PXLongRunStatus status, PXGraph graph)
{
if (status == PXLongRunStatus.Completed && graph is <YourQuoteGraphType>)
{
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
}
}
// Long Operation Method
public virtual void CreateSalesOrderMethod(CRQuote quote, List<CROpportunityProducts> QuoteList)
{
// Your code to create SO....
if (var_orderCreated)
{
PXLongOperation.SetCustomInfo(new SORedirectionCustomInfo(orderGraphObjet));
}
}
This should be able to redirect successfully once the long operation is completed and the order is created.
I have customized the "Action Email Invoice / Memo" action on the Invoices and Memos AR301000 screen.
enter image description here
Each time you click on that action, a panel will appear to load an xml file.
enter image description here
After pressing the "CARGAR" button the panel should close, however it continues to open again and again and I don't know the reason for this.
enter image description here
public PXAction<ARInvoice> notification;
[PXUIField(DisplayName = "Notifications", Visible = false)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
protected virtual IEnumerable Notification(PXAdapter adapter,
[PXString]
string notificationCD)
{
cargarXML();
foreach (ARInvoice doc in adapter.Get())
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("DocType", doc.DocType);
parameters.Add("RefNbr", doc.RefNbr);
ARContact ar = Base.Billing_Contact.Select(this, doc.BillContactID);
if (String.IsNullOrEmpty(ar.Email))
{
var param = new List<PXSPParameter>();
PXSPParameter p1 = new PXSPInParameter("#CompanyID", PXDbType.Int, PX.Data.Update.PXInstanceHelper.CurrentCompany);
PXSPParameter p2 = new PXSPInParameter("#CustomerID", PXDbType.Int, ar.CustomerID);
PXSPParameter p3 = new PXSPInParameter("#CustomerContactID ", PXDbType.Int, ar.CustomerContactID);
PXSPParameter p4 = new PXSPInParameter("#BillContactID ", PXDbType.Int, doc.BillContactID);
param.Add(p1);
param.Add(p2);
param.Add(p3);
param.Add(p4);
var proc = PXDatabase.Execute("XSPUpadeEmailVacio", param.ToArray());
}
using (var ts = new PXTransactionScope())
{
Base.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, doc.BranchID, parameters);
Base.Save.Press();
ts.Complete();
}
List<Guid> _attachments = new List<Guid>();
foreach (NoteDoc noteDoc in PXSelect<NoteDoc, Where<NoteDoc.noteID, Equal<Required<NoteDoc.noteID>>>>.Select(Base, doc.NoteID))
{
_attachments.Add((Guid)noteDoc.FileID);
}
foreach (CRActivity item in PXSelect<CRActivity, Where<CRActivity.refNoteID, In<Required<CRActivity.refNoteID>>>>.Select(Base, doc.NoteID))
{
if (item != null)
{
foreach (Guid item2 in _attachments)
{
var pars = new List<PXSPParameter>();
PXSPParameter p1 = new PXSPInParameter("#CompanyID", PXDbType.Int, PX.Data.Update.PXInstanceHelper.CurrentCompany);
PXSPParameter p2 = new PXSPInParameter("#FileID", PXDbType.UniqueIdentifier, item2);
PXSPParameter p3 = new PXSPInParameter("#NoteID", PXDbType.UniqueIdentifier, item.NoteID);
pars.Add(p1);
pars.Add(p2);
pars.Add(p3);
var proc = PXDatabase.Execute("XSPInsertarNoteDoc", pars.ToArray());
}
var par = new List<PXSPParameter>();
PXSPParameter p01 = new PXSPInParameter("#CompanyID", PXDbType.Int, PX.Data.Update.PXInstanceHelper.CurrentCompany);
PXSPParameter p02 = new PXSPInParameter("#NoteID", PXDbType.UniqueIdentifier, item.NoteID);
par.Add(p01);
par.Add(p02);
var proce = PXDatabase.Execute("XSPModificarEmail", par.ToArray());
}
}
yield return doc;
}
}
public virtual void cargarXML()
{
if (Base.Document.AskExt() == WebDialogResult.OK)
{
PX.SM.FileInfo fileInfo = PX.Common.PXContext.SessionTyped<PXSessionStatePXData>().FileInfo["CargaSessionKey"];
string result = System.Text.Encoding.UTF8.GetString(fileInfo.BinData);
ARInvoice ari = Base.Document.Current;
xtFECodHashEntry graph2 = PXGraph.CreateInstance<xtFECodHashEntry>();
var pchExt = ari.GetExtension<ARRegisterExt>();
string Valor = "";
XmlDocument xm = new XmlDocument();
xm.LoadXml(result);
XmlNodeList elemList = xm.GetElementsByTagName("ds:DigestValue");
for (int i = 0; i < elemList.Count; i++)
{
Valor = (elemList[i].InnerXml);
break;
}
PXLongOperation.StartOperation(Base, delegate ()
{
xtFECodHash dac = new xtFECodHash();
dac.RefNbr = ari.RefNbr;
dac.DocType = ari.DocType;
dac.Nrocomprobante = ari.InvoiceNbr;
dac.Hash = Valor;
dac.Tipo = pchExt.UsrTDocSunat;
graph2.xtFECodHashs.Insert(dac);
graph2.Actions.PressSave();
//Base.Document.Cache.Persist(PXDBOperation.Insert);
});
//Base.Actions.PressSave();
//}
}
}
I would first check your SmartPanel buttons. Here is an example of an "Update" Button that triggers an action and closes:
<px:PXButton ID="btnOKGasCost" runat="server" DialogResult="OK" Text="Update">
<AutoCallBack Target="formUpdateGasCost" Command="Save" />
</px:PXButton>
The target form is the FormView formUpdateGasCost that it is contained in.
The smartpanel has the defined tags of enabling the callback as fields change, the main filter/DAC object bound to it, as well as calling the AcceptButtonID
<px:PXSmartPanel ID="pnlUpdateGasCost" runat="server" Caption="Update Gas Cost"
CaptionVisible="true" DesignView="Hidden" LoadOnDemand="true" Key="UpdateGasCostFilter" CreateOnDemand="false" AutoCallBack-Enabled="true"
AutoCallBack-Target="formUpdateGasCost" AutoCallBack-Command="Refresh" CallBackMode-CommitChanges="True" CallBackMode-PostData="Page"
AcceptButtonID="btnOKGasCost">
I see that you are using the AskExt method on your function. If the above changes do not work, I would try moving the bound DAC to a Filter, and calling AskExt from the filter. For example, mine is set as:
public PXFilter<UpdateGasCostFilter> UpdateGasCostFilter;
public PXAction<CYGas> UpdateGasCost;
[PXUIField(DisplayName = "Update Gas Cost", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton]
public virtual IEnumerable updateGasCost(PXAdapter adapter)
{
var Result = UpdateGasCostFilter.AskExt(true);
if(Result == WebDialogResult.OK)
{
// perform the update actions
}
return adapter.Get();
}
I hope this helps.
I'm testing ServiceStack.OrmLite.Oracle (5.5.1) but can't save data to database when create model with Sequence attribute. Try to test with API & generated SQL, API not insert data but generated SQL is correct. How to fix this?
using System;
using System.Data;
using NUnit.Framework;
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
namespace Tests
{
public class DatabaseTest
{
private readonly IDbConnection _db;
public DatabaseTest()
{
var dbFactory = new OrmLiteConnectionFactory(
#"Data Source = (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ora-test)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = twcms12c))); User Id=scott; Password=Ab123456",
OracleDialect.Provider);
_db = dbFactory.OpenDbConnection();
}
[Test]
public void CustomerInsertTest()
{
_db.DropAndCreateTable<Person>();
var customer = new Person {FirstName = "John", LastName = "Smith", Age = 20};
//Insert by API not work
_db.Insert(customer);
var customers = _db.Select<Person>();
Console.WriteLine("Person count (API) = {0}",customers.Count);
//Insert by SQL working
_db.ExecuteSql(_db.ToInsertStatement(customer));
customers = _db.Select<Person>();
Console.WriteLine("Person count (SQL) = {0}",customers.Count);
}
}
public class Person
{
[AutoIncrement]
[Sequence("PERSON_SEQ")]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
}
}
And output result is:
Person count (API) = 0
Person count (SQL) = 1
In ServiceStack.OrmLite.Oracle (5.5.1) have a bug in method GetNextValue (ServiceStack.OrmLite.Oracle.OracleOrmLiteDialectProvider.cs):
private object GetNextValue(IDbCommand dbCmd, string sequence, object value)
{
if (value.ToString() != "0")
{
object retObj;
if (long.TryParse(value.ToString(), out var nv))
{
LastInsertId = nv;
retObj = LastInsertId;
}
else
{
LastInsertId = 0;
retObj = value;
}
return retObj;
}
dbCmd.CommandText = $"SELECT {Quote(sequence)}.NEXTVAL FROM dual";
long result = (long)dbCmd.LongScalar();
LastInsertId = result;
return result;
}
I change it to:
private object GetNextValue(IDbCommand dbCmd, string sequence, object value)
{
if (value.ToString() != "0")
{
object retObj;
if (long.TryParse(value.ToString(), out var nv))
{
LastInsertId = nv;
retObj = LastInsertId;
}
else
{
LastInsertId = 0;
retObj = value;
}
return retObj;
}
var lastSql = dbCmd.CommandText;
dbCmd.CommandText = $"SELECT {Quote(sequence)}.NEXTVAL FROM dual";
long result = (long)dbCmd.LongScalar();
LastInsertId = result;
dbCmd.CommandText = lastSql;
return result;
}
and it work well.
P/s: I have create a pull request it was accepted by ServiceStack.