Skip to main content
Solved

Dynamic change user-defined field


Forum|alt.badge.img

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:

 

Best answer by darylbowman

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.

View original
Did this topic help you find an answer to your question?

7 replies

darylbowman
Captain II
Forum|alt.badge.img+13

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?


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 22 replies
  • May 10, 2023
darylbowman wrote:

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?


darylbowman
Captain II
Forum|alt.badge.img+13

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.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 22 replies
  • May 10, 2023
darylbowman wrote:

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

 


darylbowman
Captain II
Forum|alt.badge.img+13

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.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 22 replies
  • May 11, 2023
darylbowman wrote:

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.

Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 22 replies
  • May 11, 2023
darylbowman wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings