Solved

Dynamic change user-defined field

  • 10 May 2023
  • 7 replies
  • 128 views

Userlevel 2
Badge

I need update on fly user-defined field if Project on Expense Receipt page was changed. Like it is happened for Customer and Location fileds automatically, select new project and this field should update. Can somebody help how I can implement it - what is the best way for it. I tried with Generic Inquiry and with event FieldUpdated for Project/Contract, but not yet successful.

When I tried to get to the change of the user-defined field through the event - I do not see this field in the EPExpenseClaimDetails model

I want to take value for Project Executive field from project. I added custom field to project:

 

icon

Best answer by darylbowman 11 May 2023, 00:44

View original

7 replies

Badge +11

So you have both a user-defined field and a custom field. I’m guessing you’ve tried both and just want one or the other to work.

 

Could you post your FieldUpdated event code here? Also, did you create a CacheExtension for the Expense Receipt?

Userlevel 2
Badge

So you have both a user-defined field and a custom field. I’m guessing you’ve tried both and just want one or the other to work.

 

Could you post your FieldUpdated event code here? Also, did you create a CacheExtension for the Expense Receipt?

Yes. On the project custom field. On the Receipt - user-defined field

protected void EPExpenseClaimDetails_ContractID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (EPExpenseClaimDetails)e.Row;

PM.PMProject project = PXSelect<PM.PMProject, Where<PM.PMProject.contractID, Equal<Required<PM.PMProject.contractID>>>>.Select(Base, row.ContractID);
if (project == null)
{
return;
}
var pmExtension = project.GetExtension<CD.PMPECSTFLD.CDPMProjectExt>();
if (pmExtension == null)
{
return;
}
cache.SetValueExt(row, "AttributePROJEXEC", pmExtension.UsrCDExecID);
}

This code works wrong, I think because selectors. I am getting wrong value CDPMProjectExt from project. Or I should understand how find employee with this selector ID. For example I set up employee ID 1, but from the project selector I get value 123
Also, did you create a CacheExtension for the Expense Receipt? - No, I didn’t. Can it help me?

Badge +11

Oh, I see now. You have a custom field on Project called ‘Project Executive’ and you want to set this value on Expense Receipts when the Project is changed.

Please post the CDPMProjectExt cache extension where the UsrCDExecID field is defined, and also please post a screenshot of the ‘Project Executive’ attribute configuration.

Userlevel 2
Badge

Oh, I see now. You have a custom field on Project called ‘Project Executive’ and you want to set this value on Expense Receipts when the Project is changed.

Please post the CDPMProjectExt cache extension where the UsrCDExecID field is defined, and also please post a screenshot of the ‘Project Executive’ attribute configuration.

CDPMProjectExt:
namespace CD.PMPECSTFLD
{
public class CDPMProjectExt : PXCacheExtension<PMProject>
{
public CDPMProjectExt();

[Owner(DisplayName = "Project Executive")]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public int? UsrCDExecID { get; set; }

public static bool IsActive();

public abstract class usrCDExecID : BqlType<IBqlInt, int>.Field<usrCDExecID>
{
protected usrCDExecID();
}
}
}

‘Project Executive’ attribute configuration

 

Badge +11

Your custom field is of ‘Owner’ type, which is a Contact, I believe, where as EPEmployee is an extension of BAccount. You should look up the contact first where ContactID is equal to UsrCDExecID. Then you may be able to look up the employee based upon the Contact, but I can’t actually think through how you would do that right now.

Userlevel 2
Badge

Your custom field is of ‘Owner’ type, which is a Contact, I believe, where as EPEmployee is an extension of BAccount. You should look up the contact first where ContactID is equal to UsrCDExecID. Then you may be able to look up the employee based upon the Contact, but I can’t actually think through how you would do that right now.

Thanks for the tip, I'll look in that direction.
Userlevel 2
Badge

Your custom field is of ‘Owner’ type, which is a Contact, I believe, where as EPEmployee is an extension of BAccount. You should look up the contact first where ContactID is equal to UsrCDExecID. Then you may be able to look up the employee based upon the Contact, but I can’t actually think through how you would do that right now.

I could get user with contact ID by defContactID field. Thanks for you help!

var employee = PXSelect<EP.EPEmployee, Where<EP.EPEmployee.defContactID, Equal<Required<EP.EPEmployee.defContactID>>>>.Select(Base, "contactID");

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved