-->

Populate custom field while creating sale order fr

2019-03-04 16:19发布

问题:

I have created a custom field Contact on SO screen (SO301000). Now I need to populate these field when user Create Sales Order from Opportunity screen (CR304000). New custom field Contact is based on Customer selected in Opportunity. I can see that Customer is automatically populated when I create Sales Order from Opportunity as it is by designed. However, how can I do that same for the custom field.

I have tried extending existing CreateSalesOrder method but it seems it is not helping.

Contact Lookup (It refreshes based on Customer select in SO but not when I create SO from Opportunity)

[PXDBInt()]

[PXUIField(DisplayName = "Contact", Visibility = PXUIVisibility.Visible)]
[PXSelector(typeof(Search2<Contact.contactID,
	LeftJoin<BAccount2, On<BAccount2.bAccountID, Equal<Contact.bAccountID>>>>),
	DescriptionField = typeof(Contact.displayName), Filterable = true, DirtyRead = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Default<SOOrder.customerID>))]
[PXRestrictor(typeof(Where<Contact.contactType, NotEqual<ContactTypesAttribute.bAccountProperty>,
		And<Where<BAccount2.bAccountID, Equal<Current<SOOrder.customerID>>,
				Or<Current<SOOrder.customerID>, IsNull>>>>), PX.Objects.CR.Messages.ContactBAccountDiff)]
[PXRestrictor(typeof(Where<Contact.isActive, Equal<True>>), PX.Objects.CR.Messages.ContactInactive,
			  typeof(Contact.displayName))]

public virtual int? UsrCustContactID { get; set; }
public abstract class usrCustContactID : IBqlField { }

Contact Lookup (It is working as required when I create SO from Opportunity but does not refreshes based on Customer selection)

[PXDBInt()]

[PXDBChildIdentity(typeof(Contact.contactID))]
[PXRestrictor(typeof(Where<Contact.isActive, Equal<True>>), "Contact '{0}' is inactive or closed.", new[] { typeof(Contact.displayName) })]
[PXSelector(typeof(Search2<Contact.contactID, LeftJoin<BAccount, On<BAccount.bAccountID, Equal<Contact.bAccountID>>>, Where<Contact.contactType, Equal<ContactTypesAttribute.person>, Or<Contact.contactType, Equal<ContactTypesAttribute.lead>>>>), DescriptionField = typeof(Contact.displayName), Filterable = true)]
[PXUIField(DisplayName = "Contact")]


public virtual int? UsrCustContactID { get; set; }
public abstract class usrCustContactID : IBqlField { }

回答1:

Similar answer found here: How to pass line item custom field value to sales order from opportunity?

Can be translated to something like this from CROpportunity to SOOrder...

public class CROpportunityMaintExtension : PXGraphExtension<OpportunityMaint>
{
    [PXOverride]
    public virtual void DoCreateSalesOrder(Action del)
    {
        PXGraph.InstanceCreated.AddHandler<SOOrderEntry>(graph =>
        {
            graph.RowInserting.AddHandler<SOOrder>((cache, args) =>
            {
                var soOrder = (SOOrder)args.Row;
                CROpportunity opportunity = PXResult<CROpportunity>.Current;

                // Copy logic here...

            });
        });

        del();
    }
}


标签: acumatica