I have added a user defined checkbox UsrContractCustomer to CRCase. My first step is to try to set the checkbox when the user selects the Business Account (CustomerID).
Here is my latest attempt to set the checkbox.
protected void CRCase_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (CRCase)e.Row;
if (row.CustomerID != null)
{
//CRCaseExt rowExt = PXCache<CRCase>.GetExtension<CRCaseExt>(row);
CRCaseExt rowExt = row.GetExtension<CRCaseExt>();
rowExt.UsrContractCustomer = true;
}
}
On your field in your dac extension you should be able to use a formula to set the value. This will check or uncheck you field when the customer is entered or removed. Having the logic on the field also removes the need to write graph level changes such as events.
[PXFormula(typeof(IIf<Where<CRCase.customerID, IsNull>, False, True>))]
If you want to use the event as you have it I would try cache set value such as:
cache.SetValueExt<CRCaseExt.usrContractCustomer>(e.Row, row.CustomerID != null);
Brendan's solution is correct. In another post I retrieved the value that I wanted to use to set the user-defined field. The 'false' was replaced with a condition that sets the checkbox field.
sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, false);
Thanks for the help and support.
Related
I would like to modify the ShippedQty field by putting the same value as the OpenOrderQty field after adding the line, but that does nothing. I removed the PXDefault. The value stay at 0.00.
protected void SOShipLine_RowInserted(PXCache cache, PXRowInsertedEventArgs e, PXRowInserted InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOShipLine)e.Row;
if (row==null) {return;}
row.ShippedQty=row.OpenOrderQty;
}
Thanks.
Xavier
I would like to suggest you to not set the ShippedQty because it might have some implications as it is a calculated field. Instead, you can create a custom field and set the value of OpenOrderQty to that field.
When the RowInserted event is fired, the data has already been inserted into the cache so it's too late to try and edit the data. You should change this to use a RowInserting() event. See more details here
I have a checkbox on a DAC extension to the BAccount that I want to use to set a checkbox on Case when a customer is selected. Here is what the checkbox looks like on the Business Account screen.
Here is the field on the Case screen that I want to set when the customer is selected.
I found a stack overflow question where a couple of custom fields on a customer screen were to be copied to custom fields on a sales order. I have tried to substitute my fields into the code but I haven't been able to make it work.
Here is what I have tried. I'm not sure what I am missing.
protected void CRCase_CustomerID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
var crcase = e.Row as CRCase;
if (crcase.CustomerID != null)
{
var customer = PXSelectorAttribute.Select<CRCase.customerID>(sender, crcase) as BAccountR;
if (customer != null)
{
var customerExt = customer.GetExtension<BAccountExt>();
var crcaseExt = crcase.GetExtension<CRCaseExt>();
crcaseExt.UsrContractCustomer = customerExt.UsrSage100;
}
}
}
I do not understand why BAccountR is used instead of just BAccount. Neither works right now.
I solved the issue by combining are response I received on an earlier post. I modified the last two line as follows:
var customerExt = customer.GetExtension<BAccountExt>();
//var crcaseExt = crcase.GetExtension<CRCaseExt>();
//crcaseExt.UsrContractCustomer = customerExt.UsrSage100;
sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, customerExt.UsrSage100 != null);
So here is the final issue that I need to resolve. The checkbox I used on the Business Account screen opens a new tab that displays custom fields. These custom fields are an extension of the BAccount DAC called DSDSage100. It is similar to the extension of the BAccount called Customer. In the DSDSage100 extension there is a field called UsrContractCustomer. That is the field that I want to read and set the Case field to the same value. Here is what the Sage 100 Tab looks like. I have a using directive for my project but I can't find the right reference to the DSDSage100 extension.
var customerExt = customer.GetExtension<DSDSage100>();
sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, customerExt.UsrContractCustomer != null);
Acumatica provided the answer. While I "extended the BAccount DAC" with my custom table (DSDSage100, similar to the way Customer is an extension of the BAccount DAC), it is it's own DAC. The solution was:
DSDSage100 mydac = PXSelect<DSDSage100, Where<DSDSage100.bAccountID, Equal<Required<DSDSage100.bAccountID>>>>.Select(Base, crcase.CustomerID);
sender.SetValueExt<CRCaseExt.usrContractCustomer>(crcase, mydac.UsrContractCustomer != null);
Thanks for the help and support.
I have had set my custom field 'UsrPrintQty' to be enabled on POReceiptLine_RowSelected event as below:
protected void POReceiptLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (POReceiptLine)e.Row;
PXUIFieldAttribute.SetEnabled<POReceiptLineExt.usrPrintQty>(cache, row, true);
//PXUIFieldAttribute.SetEnabled(cache, row, "UsrPrintQty", true);
}
And it is working perfectly on my development server with the Acumatica version 18.200.0075. But when I published the customization to the another instance with the version 18.112.0019, it just doesn't work.
I debug the code and the line is being hit too.
I set the highest customization level guessing there might be chance that other code is overriding this one.
I restart the application via Apply Updates.
I even changed the event from RowSelected to RowSelecting.
I tried the different overloaded method of SetEnabled (which is commented in the above code).
But nothing works.
If I put these two lines:
cache.AllowUpdate = true;
Base.transactions.Cache.AllowUpdate = true;
then it allows me to update but then I can update the whole row which I don't want to.
I also set the field property AllowUpdate to true.
But still no luck.
Thank you.
The cache AllowUpdate method takes precedence on SetEnabled method.
Calling the cache AllowUpdate with false parameter is commonly used on closed document to prevent any modification.
If you require the user to be able to modify one field of a closed document you'll have to jump through some hoops. Setting AllowUpdate to true after the base graph has set it to false is necessary.
Try this pattern:
// Required to enable any field
Base.transactions.Cache.AllowUpdate = true;
// Set all fields to false
PXUIFieldAttribute.SetEnabled(Base.transactions.Cache, null, false);
// Set the only field we want to enable to true
PXUIFieldAttribute.SetEnabled<POReceiptLineExt.usrPrintQty>(Base.transactions.Cache, null, true);
Client has an Customised field called “Approval Type” on the Purchase Order Entry screen (screenshot attached). By Default this field is available when user creates an Order.
We are implementing the Approval Workflow for this client. The client wants that when a new PO is created, this field should be disabled. But once the PO is approved and user wants to make any change in the approved PO, On selecting “Hold” checkbox option, this field should be active and user should then be allowed to set any value from the field list and save the Order. I tried the Automation steps but could not figure out how to achieve it.
Many Thanks
In the rowselected event of the POOrder, add your conditions and use the PXUIFieldAttribute.SetVisible to hide/show your field.
It will be something like below.
protected virtual void POOrder_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected del)
{
if (e.Row == null) return;
if (del != null) del(sender, e);
PXUIFieldAttribute.SetVisible<YOUR custom FIELD>(sender, e.Row, <Your true condition to show>);
}
We Have Contact Entities in contact Entitie one lookup filed company Name in that lookup having two values 1.Account and 2.Contact . When we are selecting contact show the address filed when we select account hide the address filed we needs to write the plugin to Execute that works. Kindly any one help me on the same.
Thanks!!
Rajesh Singh
First, if you need to make change on a form, you can't use plug-ins. Plug-ins are made for bussinees logics, like Update another record when the first one is created, make complex logic, etc...
What you need it is a javascript that executes on the OnLoad of the form and OnChange event in that OptionSet.
The lines you are looking for are:
function ShowField()
{
// The field is present on the form so we can access to its methods
var optionSet = Xrm.Page.getAttribute("custom_attribute");
if (optionSet == undefined)
{
return;
}
// The control is present on the form so we can access to its methods
var controlAddress = Xrm.Page.getControl("custom_address");
if (controlAddress == undefined)
{
return;
}
var valueOptionSet = optionSet.getValue(); // This is the value you set creating the OptionSet
switch (valueOptionSet)
{
case 0: // Your account value, show
controlAddress.setVisible(true);
case 1: // Your contact value, hide
controlAddress.setVisible(false);
default:
return;
}
}
You need to register a web resource and register the event, if you need more information about the code or why this stuff is here and why this not just tell me.