I want to run validation when clicking a button that, if the validation passes, would also close the smart panel. Is there a way to programmatically close a smart panel?
First - on SmartPanel you need to add a button and set property "Dialog Result" with "OK" value.
px:PXButton runat="server" ID="OkButton" Text="Ok" DialogResult="OK"
Second - you can use the bellow code (it was written stackOverflow editor, but you may understand the ideea)
public partial class ARInvoiceEntrySnrExt : PXGraphExtension<ARInvoiceEntry>
{
public PXAction<ARInvoice> paySmartPanelAction
[PXUIField(DisplayName = "Payment details", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable PaySmartPanelAction(PXAdapter adapter)
{
WebDialogResult result = this.SmartPanelDataView.AskExt();
if (result == WebDialogResult.OK)
{
var isValid = this.ValidateSmartPanelFields() //validation method everithing you may need
if (isValid == false)
{
throw new PXArgumentException(CstAPMessages.InvalidDetails, (Exception)null);
}
}
}
public virtual bool ValidateSmartPanelFields()
{
bool isValid = true;
foreach (DataViewDetail detail in this.SmartPanelDataView.Select())
{
if (detail.FieldName <= 0)
{
cache.RaiseExceptionHandling<DataViewDetail.fieldName>(detail, detail.FieldName, new PXSetPropertyException(CstAPMessages.AmountPaidMustBeGreater));
isValid = false;
}
}
return isValid;
}
}
Related
I have a need to modify the behavior of the Create Sales Order action on the Opportunity screen.
I'm trying to find the best / least intrusive method possible. I have a snippet of the base code below.
The changes I need to make are relatively simple. I need to populate some custom fields that exist on new SO.
What's the best approach?
public PXAction<CROpportunity> createSalesOrder;
[PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
{
foreach (CROpportunity opportunity in adapter.Get<CROpportunity>())
{
Customer customer = (Customer)PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<CROpportunity.bAccountID>>>>
.SelectSingleBound(this, new object[] { opportunity });
if (customer == null)
{
throw new PXException(Messages.ProspectNotCustomer);
}
if (CreateOrderParams.AskExtFullyValid((graph, viewName) => { }, DialogAnswerType.Positive))
{
Actions.PressSave();
PXLongOperation.StartOperation(this, delegate()
{
var grapph = PXGraph.CreateInstance<OpportunityMaint>();
grapph.Opportunity.Current = opportunity;
grapph.CreateOrderParams.Current = CreateOrderParams.Current;
grapph.DoCreateSalesOrder(CreateOrderParams.Current);
});
}
yield return opportunity;
}
}
protected virtual void DoCreateSalesOrder(CreateSalesOrderFilter param)
{
bool recalcAny = param.RecalculatePrices == true ||
param.RecalculateDiscounts == true ||
param.OverrideManualDiscounts == true ||
param.OverrideManualDocGroupDiscounts == true ||
param.OverrideManualPrices == true;
var opportunity = this.Opportunity.Current;
Customer customer = (Customer)PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<CROpportunity.bAccountID>>>>.Select(this);
A simple override should accomplish your goal. Below is an example, which injects custom logic into the event handler SOOrder.RowInserted, during the Create Sales Order action. Then allow the action to finish normally. This approach extends the action with your custom logic, while retaining base code of the Action.
public class OpportunityMaint_Extension : PXGraphExtension<OpportunityMaint>
{
public delegate IEnumerable CreateSalesOrderDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable CreateSalesOrder(PXAdapter adapter, CreateSalesOrderDelegate baseMethod)
{
PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
{
graph.RowInserted.AddHandler<SOOrder>((sender, e) =>
{
SOOrder order = (SOOrder)e.Row;
SOOrderExt orderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(order);
orderExt.UsrCustomOne = "Howdy"; //assign anything you want here
});
});
return baseMethod(adapter);
}
}
}
I have a customization Project that requires me to only show data (like Opportunities) that have been setup in added customization tab in Business Account. I've manage to comply these using data view delegate and a custom selector, The error occurs when:
1.) clicking an opportunity ID where the customization restricts such data in the generic inquiry.
2.) clicking next or previous button in the opportunities module
Here is the Code
protected virtual IEnumerable opportunity()
{
var output = new PXSelect<CROpportunity>(Base);
foreach (CROpportunity _output in output.Select())
{
bool returnOutput = false;
var memberships = PXSelectJoinGroupBy<EPEmployee, RightJoin<EPCompanyTreeMember, On<EPCompanyTreeMember.userID, Equal<EPEmployee.userID>>>, Where<EPEmployee.userID, Equal<Current<AccessInfo.userID>>>, Aggregate<GroupBy<EPCompanyTreeMember.workGroupID>>>.Select(Base);
foreach (PXResult<EPEmployee, EPCompanyTreeMember> member in memberships)
{
EPCompanyTreeMember _member = (EPCompanyTreeMember)member;
BAccountRestriction2 visible = PXSelect<BAccountRestriction2, Where<BAccountRestriction2.account, Equal<Required<BAccount.bAccountID>>, And<BAccountRestriction2.child, Equal<Required<BAccountRestriction2.child>>>>>.Select(Base, ((CROpportunity)_output).BAccountID, _member.WorkGroupID);
if (visible != null || ((CROpportunity)_output).OpportunityID == " <NEW>")
{
returnOutput = true;
break;
}
}
if (returnOutput)
{
yield return _output;
}
}
}
Here is the Custom Selector
public class OpportunityMaintExtension : PXGraphExtension<OpportunityMaint>
{
#region custom selector
public class PXCustomSelectorOpportunityAttribute : PXCustomSelectorAttribute
{
public PXCustomSelectorOpportunityAttribute()
: base(typeof(CROpportunity.opportunityID)
, new[] { typeof(CROpportunity.opportunityID),
typeof(CROpportunity.opportunityName),
typeof(CROpportunity.status),
typeof(CROpportunity.curyAmount),
typeof(CROpportunity.curyID),
typeof(CROpportunity.closeDate),
typeof(CROpportunity.stageID),
typeof(CROpportunity.cROpportunityClassID),
typeof(BAccount.acctName),
typeof(Contact.displayName) }
)
{
//this.DescriptionField = typeof(CQHRISLeave.refNbr);
}
protected virtual IEnumerable GetRecords()
{
foreach (var pc in this._Graph.GetExtension<OpportunityMaintExtension>().opportunity())
{
if (((CROpportunity)pc).OpportunityID != " <NEW>")
yield return pc as CROpportunity;
}
}
}
#endregion
And then the implementation of the custom selector attribute is here:
public class CROpportunityExtension : PXCacheExtension<CROpportunity>
{
#region OpportunityID
public abstract class opportunityID : PX.Data.IBqlField { }
public const int OpportunityIDLength = 10;
[PXDBString(OpportunityIDLength, IsUnicode = true, IsKey = true, InputMask = ">CCCCCCCCCCCCCCC")]
[PXUIField(DisplayName = "Opportunity ID", Visibility = PXUIVisibility.SelectorVisible)]
[AutoNumber(typeof(CRSetup.opportunityNumberingID), typeof(AccessInfo.businessDate))]
[NORDE.OpportunityMaintExtension.PXCustomSelectorOpportunity]
[PXFieldDescription]
public virtual String OpportunityID { get; set; }
#endregion
}
I've managed to "resolve" this issue by disabling the generic inquiry on this page. Initially, Opportunities page is a generic inquiry, for some reason, it may have affected the cache or the data view delegate and throws an error.
I simply: Edit Generic inquiry -> Entry Point Tab -> Uncheck "Replace Entry Screen with this Inuiry in Menu"
I have added a custom save button in Sales Order screen in place of my current one. How do I reorder the main toolbar so that new save button is in place of the old one? You can do this easily for grid buttons, but for header ones it is not so obvious.
The order of the buttons is based on the order of the PXActions in the graph.
(1) In this example my save button is first, then cancel button second.
public class MyGraph : PXGraph<MyGraph>
{
public PXSave<MyPrimaryDac> Save;
public PXCancel<MyPrimaryDac> Cancel;
}
(2) In this example my cancel button is first, then save button second.
public class MyGraph : PXGraph<MyGraph>
{
public PXCancel<MyPrimaryDac> Cancel;
public PXSave<MyPrimaryDac> Save;
}
Note that PXSave and PXCancel are PXActions.
Edit: from comments and question edits if you are extending another graph you should be able to use a new class inherited from PXSave and set the property name the same ("Save" in the example of sales order). Here is something that should work for an override to the save button and asking the user a question and keeps the save button in the same button location...
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public SalesPXSave<SOOrder> Save;
public class SalesPXSave<TNode> : PXSave<TNode> where TNode : class, IBqlTable, new()
{
public SalesPXSave(PXGraph graph, string name) : base(graph, name)
{
}
public SalesPXSave(PXGraph graph, Delegate handler) : base(graph, handler)
{
}
[PXSaveButton]
[PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
protected override IEnumerable Handler(PXAdapter adapter)
{
bool someCondition = true;
if (someCondition)
{
if (adapter.View.Ask(adapter.View.Graph.Caches[typeof(TNode)].Current, "Hi User",
MessageButtons.YesNo) != WebDialogResult.Yes)
{
return adapter.Get();
}
}
return base.Handler(adapter);
}
}
}
Edit: For reference here are some quick untested examples of extending RowPersisting or the Persist in an extension if this is preferred vs extending the buttons...
[PXOverride]
public virtual void Persist(Action del)
{
if (Base.Document.Ask(Base.Document.Current, "Question", "Continue?",
MessageButtons.YesNo) != WebDialogResult.Yes)
{
return;
}
del?.Invoke();
}
protected virtual void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting del)
{
var row = (SOOrder)e.Row;
if (row == null)
{
return;
}
if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update || e.Operation == PXDBOperation.Delete) &&
Base.Document.Ask(row, "Question", "Continue ?", MessageButtons.YesNo, true) != WebDialogResult.Yes)
{
e.Cancel = true;
return;
}
del?.Invoke(cache, e);
}
I am trying to add Add Items functionality in Opportunity like in Sales Order. I have gone through the code in SOOrderEntry and I have tried to replicate the same functionality.
The Add Item menu brings the smart panel with filter options, but it does not populate the data. I have compared the setting with Sales Order Add Item Smart panel settings and I did not miss anything.
I have replicated the table structure and events as in sales order with changes required for Opportunity.
#region SiteStatus Lookup
public PXFilter<OpportunitySiteStatusFilter> oppsitestatusfilter;
[PXFilterable]
[PXCopyPasteHiddenView]
public OpportunityStatusLookup<OpportunitySiteStatusSelected, OpportunitySiteStatusFilter> opportunitysitestatus;
public PXAction<CROpportunity> addOppBySite;
[PXUIField(DisplayName = "Add Stock Item", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public virtual IEnumerable AddOppBySite(PXAdapter adapter)
{
oppsitestatusfilter.Cache.Clear();
if (opportunitysitestatus.AskExt() == WebDialogResult.OK)
{
return AddOppSelBySite(adapter);
}
oppsitestatusfilter.Cache.Clear();
opportunitysitestatus.Cache.Clear();
return adapter.Get();
}
public PXAction<CROpportunity> addOppSelBySite;
[PXUIField(DisplayName = "Add", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = false)]
[PXLookupButton]
public virtual IEnumerable AddOppSelBySite(PXAdapter adapter)
{
foreach (OpportunitySiteStatusSelected line in opportunitysitestatus.Cache.Cached)
{
if (line.Selected == true && line.QtySelected > 0)
{
CROpportunityProducts newline = PXCache<CROpportunityProducts>.CreateCopy(Base.Products.Insert(new CROpportunityProducts()));
newline.SiteID = line.SiteID;
newline.InventoryID = line.InventoryID;
newline.SubItemID = line.SubItemID;
newline.UOM = line.SalesUnit;
//newline.AlternateID = line.AlternateID;
//newline = PXCache<SOLine>.CreateCopy(Transactions.Update(newline));
//if (newline.RequireLocation != true || PXAccess.FeatureInstalled<FeaturesSet.warehouseLocation>())
// newline.LocationID = null;
newline = PXCache<CROpportunityProducts>.CreateCopy(Base.Products.Update(newline));
//newline.Qty = line.QtySelected;
cnt = 0;
Base.Products.Update(newline);
}
}
opportunitysitestatus.Cache.Clear();
return adapter.Get();
}
protected virtual void OpportunitySiteStatusFilter_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
{
OpportunitySiteStatusFilter row = (OpportunitySiteStatusFilter)e.Row;
if (row != null && Base.Products.Current != null)
row.SiteID = Base.Products.Current.SiteID;
}
int cnt;
public IEnumerable<PXDataRecord> ProviderSelect(BqlCommand command, int topCount, params PXDataValue[] pars)
{
cnt++;
return Base.ProviderSelect(command, topCount, pars);
}
#endregion
Regards,
R. Muralidharan
You may want to compare your custom SmartPanel aspx with out-of-box Add Stock Item SmartPanel of SalesOrderEntry screen. As #Hybridzz mentioned, most likely you haven’t set AutoSize property. You need to set AutoSize to True when Grid pagination is Enabled.
Hi I am trying to extend the ARPaymentEntry graph so I can do some extra stuff when the user releases the payment.
I have extended the paymententry graph and copied the Release action over like so
public PXAction<ARPayment> release;
[PXUIField(DisplayName = "Release", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton]
public virtual IEnumerable Release(PXAdapter adapter)
{
PXCache cache = Base.Document.Cache;
List<ARRegister> list = new List<ARRegister>();
foreach (ARPayment ardoc in adapter.Get<ARPayment>())
{
if (!(bool)ardoc.Hold)
{
cache.Update(ardoc);
list.Add(ardoc);
}
}
if (list.Count == 0)
{
throw new PXException(Messages.Document_Status_Invalid);
}
Base.Save.Press();
PXLongOperation.StartOperation(this, delegate()
{
if (SyncPaymentToRex(list))
{
ARDocumentRelease.ReleaseDoc(list, false);
}
});
return list;
}
If you look at the PXLongOperation I have a my own method I want to pass before it goes and releases the document.
Now this works for me but there is no user feedback on the screen (e.g. the controls arent disabled, no processing icon appears while its performing the operation etc) and also the screen doesnt reload, I have to manually reload the page before I can see the payment has been release etc
Can I get some help so I can get the page updating and reacting like it usually does on release but with my code in there as well?
Try this
public PXAction<ARPayment> release;
[PXUIField(DisplayName = "Release", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton]
[PXOverride]
public virtual IEnumerable Release(PXAdapter adapter)
{
PXCache cache = Base.Document.Cache;
List<ARRegister> list = new List<ARRegister>();
foreach (ARPayment ardoc in adapter.Get<ARPayment>())
{
if (!(bool)ardoc.Hold)
{
cache.Update(ardoc);
list.Add(ardoc);
}
}
if (list.Count == 0)
{
throw new PXException(Messages.Document_Status_Invalid);
}
Base.Save.Press();
PXLongOperation.StartOperation(this.Base, delegate()
{
if (SyncPaymentToRex(list))
{
ARDocumentRelease.ReleaseDoc(list, false);
}
});
return list;
}