Made the journal entry description field mandatory with below code:
using PX.Objects.CR;
using PX.Data.EP;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using PX.Api;
using PX.Data;
using PX.Common;
using PX.Objects.Common;
using PX.Objects.CS;
using PX.Objects.CM;
using PX.Objects.CA;
using PX.Objects.FA;
using PX.Objects.GL.JournalEntryState;
using PX.Objects.GL.JournalEntryState.PartiallyEditable;
using PX.Objects.GL.Overrides.PostGraph;
using PX.Objects.GL.Reclassification.UI;
using PX.Objects.PM;
using PX.Objects.TX;
using PX.Objects;
using PX.Objects.GL;
namespace PX.Objects.GL
{
public class JournalEntry_Extension:PXGraphExtension<JournalEntry>
{
#region Event Handlers
//start my code
[PXDefault]
[PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
//end my code
[PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.Visible)]
[PXDBString(255, IsUnicode = true)]
protected virtual void Batch_Description_CacheAttached(PXCache cache)
{
}
#endregion
}
}
however, I receive an error message when browsing records as below:
Error:
Error: An error occurred during processing of the field Description : Unable to cast object of type 'System.Boolean' to type 'System.String'..
Not sure what I'm doing wrong
Thanks
You could set the Required property to True using PXUIField Attribute. See sample below (Please notice that there are NO quotes on Required Property):
public class JournalEntry_Extension : PXGraphExtension<JournalEntry>
{
#region Event Handlers
[PXDefault]
[PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.Visible, Required = true)]
[PXDBString(255, IsUnicode = true)]
protected virtual void Batch_Description_CacheAttached(PXCache cache)
{
}
#endregion
}
Related
Situation:
I have to asign price per subitem on both the Vendor Price Worksheets screen and Vendor Prices screen.
When the release button is pressed in Vendor Price Worksheets, the records in the APPriceWorksheetDetail table have to be created in the APVendorPrice table, Obviously I have to assign the SubItemID field value of the APPriceWorksheetDetail table to the UsrSubItemID field of the APVendorPrice table.
Notes:
It was not necessary to create the SubItemID field in Vendor Price Worksheets grid because it already existed in Details dataview.
I created the SubItemID field in Vendor Prices grid because it didn't exist in Records dataview.
This is my Vendor Price Worksheets screen
This is my Vendor Prices screen
This is my APVendorPriceExtensions DAC
using PX.Data;
using PX.Objects.AP;
using PX.Objects.CM;
using PX.Objects.IN;
using PX.Objects.CS;
using PX.Objects;
using System.Collections.Generic;
using System;
namespace PX.Objects.AP
{
public class APVendorPriceExt : PXCacheExtension<PX.Objects.AP.APVendorPrice>
{
#region UsrSubItemID
[PXDefault(typeof(Search<InventoryItem.defaultSubItemID,
Where<InventoryItem.inventoryID, Equal<Current<APVendorPrice.inventoryID>>,
And<InventoryItem.defaultSubItemOnEntry, Equal<boolTrue>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Default<APVendorPrice.inventoryID>))]
[SubItem(typeof(APVendorPrice.inventoryID))]
public virtual int? UsrSubItemID { get; set; }
public abstract class usrSubItemID : PX.Data.BQL.BqlInt.Field<usrSubItemID> { }
#endregion
}
}
I found the method that assigns the values in APPriceWorkSheetMain graph, the method is called CreateSalesPrice, I'm trying to override that method putting my custom UsrSubItemID field but I get the following error: "CS0117: 'APVendorPrice' does not contain a definition for 'UsrSubItemID'".
This is my APPriceWorkSheetMain_Extension
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.Common;
using PX.Objects.Common.Extensions;
using PX.Objects.CS;
using PX.Objects.CM;
using PX.Objects.IN;
using PX.Objects.GL;
using PX.Api;
using PX.Objects;
using PX.Objects.AP;
namespace PX.Objects.AP
{
public class APPriceWorksheetMaint_Extension : PXGraphExtension<APPriceWorksheetMaint>
{
#region Event Handlers
public delegate APVendorPrice CreateSalesPriceDelegate(APPriceWorksheetDetail priceLine, Nullable<Boolean> isPromotional, Nullable<DateTime> effectiveDate, Nullable<DateTime> expirationDate);
[PXOverride]
public APVendorPrice CreateSalesPrice(APPriceWorksheetDetail priceLine, Nullable<Boolean> isPromotional, Nullable<DateTime> effectiveDate, Nullable<DateTime> expirationDate, CreateSalesPriceDelegate baseMethod)
{
APVendorPrice newSalesPrice = new APVendorPrice
{
VendorID = priceLine.VendorID,
InventoryID = priceLine.InventoryID,
UsrSubItemID = priceLine.SubItemID,
SiteID = priceLine.SiteID,
UOM = priceLine.UOM,
BreakQty = priceLine.BreakQty,
SalesPrice = priceLine.PendingPrice,
CuryID = priceLine.CuryID,
IsPromotionalPrice = isPromotional,
EffectiveDate = effectiveDate,
ExpirationDate = expirationDate,
};
return newSalesPrice;
}
#endregion
}
}
Any advice for this?
Did you try using the following approach? (updating through the extension DAC):
APVendorPrice newSalesPrice = new APVendorPrice
{
VendorID = priceLine.VendorID,
InventoryID = priceLine.InventoryID,
SiteID = priceLine.SiteID,
UOM = priceLine.UOM,
BreakQty = priceLine.BreakQty,
SalesPrice = priceLine.PendingPrice,
CuryID = priceLine.CuryID,
IsPromotionalPrice = isPromotional,
EffectiveDate = effectiveDate,
ExpirationDate = expirationDate,
};
var vendorPriceExt = PXCache<APVendorPrice>.GetExtension<APVendorPriceExt>(newSalesPrice);
vendorPriceExt.UsrSubItemID = priceLine.SubItemID;
return newSalesPrice;
I need to add a LandedCost in PO Receipt screen (PO302000) based on a fix percentage (which I can include as a custom field in PO Preferences). It should be automatically added by the time PO Receipt is released. Which event should be the best approach to trigger and add LandedCost?
Is that when user uncheck OnHold checkbox?
Or, User clicks on Release button? If yes then can I extend release action?
The method that releases the POReceipts is static we cannot override it.
However, we can override the places where this static method is being called. It is called in two places: 1) on the release Action of POReceiptEntry(graph) and 2) on the constructor of the POReleaseReceipt(graph) that sets the process delegate.
1) On the POReceiptEntry, you can extend this graph to first do your Custom code and then call base release method.
public class POReceiptEntry_Extension:PXGraphExtension<POReceiptEntry>
{
public PXSetup<POSetup> posetup;
#region Event Handlers
public PXAction<POReceipt> release;
[PXUIField(DisplayName = Messages.Release, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton]
public virtual void Release()
{
//retrieve value from Custom field added on PO Preferences screen
//POSetup setup = posetup.Current;
//POSetupExt setupExt = setup.GetExtension<POSetupExt>();
LandedCostTran landedCost = Base.landedCostTrans.Insert();
landedCost.LandedCostCodeID = "YOURLANDEDCOSTCODE";
landedCost.InvoiceNbr = "YOURINVOICENUMBER";
landedCost.CuryLCAmount = 2; //Formula here using setupExt.UsrFieldPercentange
Base.landedCostTrans.Update(landedCost);
Base.release.Press();
}
#endregion
}
2) On the POReleaseReceipt graph, since the process delegate is set on the constructor of this graph, you can extend this graph and override Initialize() method to set your custom process delegate.
Your custom process delegate will have your custom code and then call base method.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AP;
using PX.Objects.PO;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects;
namespace PX.Objects.PO
{
public class POReleaseReceipt_Extension:PXGraphExtension<POReleaseReceipt>
{
public override void Initialize()
{
//Gets Process Delegate
var processDelegate = (PXProcessingBase<POReceipt>.ProcessListDelegate)Base.Orders.GetProcessDelegate();
//Change the process delegate that was created by the framework by your custom one.
Base.Orders.SetProcessDelegate(delegate (List<POReceipt> orders) { POReceiptsProc(orders, processDelegate); });
}
public static void POReceiptsProc(List<POReceipt> orders, PXProcessingBase<POReceipt>.ProcessListDelegate processDelegate)
{
//Execute your custom code here
//create POReceiptEntry graph, Loop through the orders, Access your Custom field, Add LandedCost
PXTrace.WriteInformation("Start Process execution");
POReceiptEntry graph = PXGraph.CreateInstance<POReceiptEntry>();
........
//Call the base action
if (processDelegate != null)
processDelegate(orders);
}
}
}
Is it possible to change the branch at runtime using code (AEF)? How can you do this at runtime? Say I have a custom Action that when clicked I want to change the company using code, how can I do that?
Below is code that can be implemented that will programmatically change the current branch.
using PX.Common;
using PX.Data;
using PX.Objects.CS;
using System.Collections;
using System.Web;
namespace AccessInfoChange
{
public class BranchMaintExtension : PXGraphExtension<BranchMaint>
{
public PXAction<BranchMaint.BranchBAccount> changeBranch;
[PXUIField(DisplayName = "Change Branch")]
[PXButton]
public virtual IEnumerable ChangeBranch(PXAdapter adapter)
{
int branchObj = 5; //BranchID of Branch you would like to switch to
PXContext.SetBranchID(branchObj);
HttpCookie branchCooky = HttpContext.Current.Response.Cookies["UserBranch"];
if (branchCooky == null)
HttpContext.Current.Response.Cookies.Add(new HttpCookie("UserBranch", "MAIN"));//BranchCD of Branch to switch
else branchCooky.Value = branchObj.ToString();//String of IntegerID for BranchID to switch
return adapter.Get();
}
}
}
I am trying to add an option under Actions in Acumatica on the Transactions screen CA304000. See below what I am trying to achieve:
using System;
using System.Collections;
using System.Collections.Generic;
using PX.Data;
using PX.Objects.Common;
using PX.Objects.AP;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.Objects.TX;
using PX.Objects.EP;
using PX.Objects.CR;
using Avalara.AvaTax.Adapter;
using Avalara.AvaTax.Adapter.TaxService;
using AvaAddress = Avalara.AvaTax.Adapter.AddressService;
using AvaMessage = Avalara.AvaTax.Adapter.Message;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects;
using PX.Objects.CA;
namespace PX.Objects.CA
{
public class CATranEntry_Extension:PXGraphExtension<CATranEntry>
{
#region Event Handlers
public override void Initialize()
{
Base.action.AddMenuAction(ShowURL);
}
public PXAction<CAAdj> ShowURL;
[PXUIField(DisplayName = "Phieu Thu")]
[PXButton]
protected virtual void showURL()
{
CAAdj doc = Base.Document.Current;
if (doc.RefNbr != null)
{
throw new PXReportRequiredException(doc, "TNCA6401", null);
}
}
#endregion
}
}
This is however telling me that there is ('PX.Objects.CA.CATranEntry' does not contain a definition for 'Document' and no extension method 'Document' accepting a first argument of type 'PX.Objects.CA.CATranEntry' could be found) twice.
this TNCA6401 only have one paramenter Reference Number. Please be specific (Image is the best). I'm Noob. Thanks you.
You should be working with CAAdjRecords data view not Document.
CAAdj doc = Base.Document.Current;
should be CAAdj doc = Base.CAAdjRecords.Current
And Reference Nbr. is tied to AdjRefNbr field.
You could use Customization -> Inspect Element to identify screen is working with which Graph, Data View, DAC and DAC field.
I am trying to add an option under Actions in Acumatica on the Checks & Payment screen AP302000. See below what I am trying to achieve:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using PX.Common;
using PX.Data;
using PX.Objects.CM;
using PX.Objects.CA;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.Objects.CR;
using PX.Objects;
using PX.Objects.AP;
namespace PX.Objects.AP
{
public class APPaymentEntry_Extension:PXGraphExtension<APPaymentEntry>
{
#region Event Handlers
public PXAction<APPayment> ShowURL;
[PXUIField(DisplayName = "Print Remittance")]
[PXButton]
protected virtual void showURL()
{
APPayment doc = Document.Current;
if (doc.RefNbr != null) {
throw new PXReportRequiredException(doc.RefNbr, "AP991000", null);
}
}
#endregion
}
}
This is however telling me that there is no definition and no extension method for 'APPayment'. Can someone please walk me through how to achieve what I am trying to do?
Note that the report has only 1 parameter (RefNbr)
Thanks,
G
To Add a new Action in existing Actions Menu, you should override the Initialize() method and use AddMenuAction.
public class APPaymentEntry_Extension : PXGraphExtension<APPaymentEntry>
{
public override void Initialize()
{
Base.action.AddMenuAction(ShowURL);
}
public PXAction<APPayment> ShowURL;
[PXUIField(DisplayName = "Print Remittance")]
[PXButton]
protected virtual void showURL()
{
APPayment doc = Base.Document.Current;
if (doc.RefNbr != null)
{
throw new PXReportRequiredException(doc, "AP991000", null);
}
}
}
Document.Current should be accessed as Base.Document.Current in Extensions. You need to pass the DAC as first parameter in PXReportRequiredException if DAC has the appropriate parameter value. Alternatively, you can build parameters and pass it to PXReportRedirectException.
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["ParameterName1"] = <Parameter Value>;
...
throw new PXReportRequiredException(parameters, <reportID>, "Report")