Inserting data into a contact

For my part, I want to add a contact, using code methods in AX2012

Please help me. Thank you

Could you provide more details about your requirements, please?

For example, do you mean a contact person or contact information, such as a phone number? To what do you want to add it? It should be obvious that nobody can write code without clarifying what the code should do?

By the way, why did yoiu attach a tag for D365FO if you say it’s about AX 2012? Let me clean it up.

Hello, MartinDrab4

I need to add a contact in ax2012 and then you can see it on the contact page of ERP

My current code is like this:

public static void main(Args _args)
{
smmContactPersonV2Entity contact;

contact.FirstName=‘hai’;
contact.MiddleName=‘gang’;
contact.LastName=‘wang’;
contact.LastNamePrefix=‘abc’;
contact.contactstype=0;
contact.name=‘hai gang wang’;
contact.contactforparty=68719509753;
contact.associatedpartynumber=‘000002456’;
contact.locator=‘15649978872’;

if(contact.validatewrite())
{
contact.insert();
}
}

I don’t know if there is a problem with the field I wrote, what other reasons are haishi

It seems that you’re trying to add a contact person to a party (using a hard-coded party ID).

Please always use Insert > Insert Code to paste source code. Among other things, it preserves indentation, making code easier to read it. Isn’t this much better?

public static void main(Args _args)
{
	smmContactPersonV2Entity contact;

	contact.FirstName = 'hai';
	contact.MiddleName = 'gang';
	contact.LastName = 'wang';
	contact.LastNamePrefix = 'abc';
	contact.ContactsType = 0;
	contact.Name = 'hai gang wang';
	contact.Contactforparty = 68719509753;
	contact.AssociatedPartyNumber = '000002456';
	contact.Locator = '15649978872';

	if (contact.validateWrite())
	{
		contact.insert();
	}
}

Unfortunately you forgot to mention what kind of problem you have with your code. Could you add this information, please?

Also, what is smmContactPersonV2Entity? I don’t remember such a table in AX 2012.

Unfortunately, my entity is refreshing and can’t run. I can see the problem in a while,

SmmContactPersonV2Entity is the value displayed in AX2012, and Contact V2 is the value displayed in Dynamics 365 finance and operation

It’s a Entity

Data entities? OData? CDS? It sounds like D365FO to me, not AX 2012.

You misinterpret the data. It says that the AOT object SmmContactPersonV2Entity has a label (= a human-friendly and translantable text) “Contacts V2”. It’s both about the same element in D365FO. It’s not about AX 2012 at all.

Please try to compile your code. I think it’ll fail to compile, because smmContactPersonV2Entity does’t exist.

You don’t have data entities in AX 2012. You will need to work with ContactPerson table directly.

yes,He is D365

Using this eventually resulted in the following warning

I’m confused. You explicitly stated that you want it “in AX2012”. Are you now saying that it was wrong and you’re actually talking about D365FO, not AX 2012?

The error message says that there is no value for ContactPersonId, although you can’t create a contact person witjhout ID. You either need to set the value by yourself or, more likely, configure the number sequence and let the system to assing IDs automatically. (It’s the sequence returned from ContactPerson::numRefContactPersonId()).

Thank you so much for your doubts