web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create customer using OData - AccountNum field using number sequence

(0) ShareShare
ReportReport
Posted on by 960

Hi All ,

I am trying to create a customer using Odata with below code :

public bool createCustomer(string targetAxLegalEntity, string custAccount, string custname, string custgrpid)
        {
            Customer custCustentity = context.CreateTrackedEntityInstance<Customer>();
            if(!customerExists(targetAxLegalEntity,custAccount))
            {
                custCustentity.DataAreaId = targetAxLegalEntity;
                custCustentity.CustomerAccount = custAccount;
                custCustentity.PartyType = "Organization";
                custCustentity.Name = custname;
                custCustentity.AddressBooks = "";
                
                custCustentity.AddressCountryRegionId = "USA";
                custCustentity.SalesCurrencyCode = "USD";
                custCustentity.CustomerGroupId = custgrpid;
                if (!SaveChanges())
                    return false;
                logMessageHandler(string.Format("created Customer '{0}' and released to com '{1}'", custCustentity.CustomerAccount, targetAxLegalEntity));

        
            }            

            return true;
        }

This is working fine and I am able to create the Customer.

However when I am trying to create Customer without passing the customer account ,it is not working throwing the error "customer account must be specified".

I have overridden the initvalue method in Customer dataentity ,however it seems this method is not getting called in Odata stack.

Can someone please help me to understand how to use Numbersequence in order to get correct CustAccount.

Thanks,

Gaurav Pandey

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at
    RE: AX 7 Create customer using Odata - Accountnum field using numbersequence

    Hi Gaurav,

    Have a look on this post to get an idea on how number sequence can be used to create new customer account daxbeginners.wordpress.com/.../how-to-create-customer-through-x

    You can also try debugging the initValue method in customer data entity to see where it is failing.

  • Gaurav Pandey Profile Picture
    960 on at
    RE: AX 7 Create customer using Odata - Accountnum field using numbersequence

    Hi Faisal ,

    Thanks for reply, however I am not creating Customer using X++ ,but Odata (C#).

    Thanks,

    Gaurav Pandey

  • Faisal Fareed Profile Picture
    10,796 User Group Leader on at
    RE: AX 7 Create customer using Odata - Accountnum field using numbersequence

    Hi Gaurav,

    I reckon this is not from C# but you can customize in AX to auto assign the number sequence for the data entity using events.

  • Suggested answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at
    RE: AX 7 Create customer using Odata - Accountnum field using numbersequence

    This will help you ax.help.dynamics.com/.../validations-defaulting-and-unmapped-fields

  • Suggested answer
    Luiz Ventura Profile Picture
    152 on at
    RE: AX 7 Create customer using Odata - Accountnum field using numbersequence

    Hello,

    Try to use "SaveChanges(SaveChangesOptions.PostOnlySetProperties)" instead of "SaveChanges()".

  • kartikkp7 Profile Picture
    365 on at
    RE: Create customer using OData - AccountNum field using number sequence

    Hi... How did you generate customer account from number sequence when inserting record through odata?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans