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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to update customer details in Ax by using AIF in C#

(0) ShareShare
ReportReport
Posted on by 360

 

Hai friends,

I need how to update Customer details by using AIF services.

 

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

 

namespace UpdateCustInfo

{

    class Program

    {

        static void Main(string[] args)

        {

            Modify.CustomerServiceClient Client = new Modify.CustomerServiceClient();

            Modify.AxdCustomer customer = new Modify.AxdCustomer();

            Modify.AxdEntity_CustTable[] custTable = new Modify.AxdEntity_CustTable[1];

 

            Modify.CallContext CallContext = new Modify.CallContext() { Company = "CEU" };

            Modify.EntityKey[] entityKeyLists = new Modify.EntityKey[1];

            Modify.EntityKey entityKeys = new Modify.EntityKey();

            Modify.KeyField[] keyDataLists = new Modify.KeyField[1];

            Modify.KeyField keyFields = new Modify.KeyField();

            keyFields.Field = "AccountNum";

           keyFields.Value = "1101";

            keyDataLists[0] = keyFields;

           entityKeys.KeyData = keyDataLists;

           entityKeyLists[0] = entityKeys;

           Modify.EntityKey[] entityKeyList = new Modify.EntityKey[1];

           Modify.EntityKey entityKey = new Modify.EntityKey();

            Modify.KeyField[] keyDataList = new Modify.KeyField[1];

            Modify.KeyField keyField = new Modify.KeyField();

            keyField.Field = "CashDisc";

            keyField.Value = "KArya";

            keyDataList[0] = keyField;

            entityKey.KeyData = keyDataList;

            entityKeyList[0] = entityKey;

            customer.CustTable = custTable;

            Client.update(CallContext, entityKeyLists, customer);

 

        }

    }

}

1780.Update-issue1.jpg

Now i am getting this error but i am unable to find this field can any one help me

 

 

*This post is locked for comments

I have the same question (0)
  • Shashi s Profile Picture
    1,203 on at

    The error message is not clear in the Snapshot.

    It would be a good idea to paste the Error message separately to the post.

    It looks as if it is a new field you have added to the Customer table?

    If you do compile on the table, i think you should get a Best practise warning to update the document service class.

    You can either do that manually or use the auto generate option.

    If you want to regenerate the Aif Document. go to Tools > AIF > Update Document service

    Select the CustCustomerService class and check the update AxBC classes

     

  • 640579632b5c4e6780a624c4771b6f93 Profile Picture
    4,730 on at

    See what from the watch window , what information you are getting into Customer object.

  • Suggested answer
    Shashi s Profile Picture
    1,203 on at

    After receiving your email,

    The missing field is ValidAsofDateTime

    This can be found in the AxdCustomer object.

    So in your example you will need to make a change

    ...

    customer.CustTable = custTable;

    customer.ValidAsOfDateTime = DateTime.Now;

    hope this helps

  • venkateswarrao v Profile Picture
    360 on at

    Still i am not getting shashi

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    should you not first use find & find key service?

    this will return the customer records, change them and send them back with the update call?

  • dynamics developer Profile Picture
    2 on at

    .AxdType_DateTime validation = new VendServiceReference.AxdType_DateTime();

     validation.localDateTime = DateTime.UtcNow;

      validation.timezone = AxdEnum_Timezone.GMTPLUS0500ISLAMABAD_KARACHI_TASHKENT;

      DateTime date = new DateTime(2013, 4, 6);

       validation.Value = date.ToUniversalTime();

        vTable.ValidAsOfDateTime = validation;

    validasofdat error is solved by this but then it says '_documenthash'  must be filled..

    so i read the record from ax and then try to upate it.. it than gave me error document hash does not match original document.  :(

    is there any documentation out there? so frustrated now

  • dynamics developer Profile Picture
    2 on at

    Hi

    To update records using AIF you first have to retrieve the records using the 'Read service".

    update the content you want to update.

    Customers.ValidAsOfDateTime = Vendors.ValidAsOfDateTime;

    Customers.DocPurpose = AxdEnum_XMLDocPurpose.Original;

    Customers.DocPurposeSpecified = true;

    where Customers are the customers read via read service

    Thanks

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    PROVEN SOLUTION!

               CustomerServiceClient svc = new CustomerServiceClient();

               //get Customer

               QueryCriteria qc = new QueryCriteria();

               qc.CriteriaElement = new CriteriaElement[1];

               qc.CriteriaElement[0] = new CriteriaElement();

               qc.CriteriaElement[0].FieldName = "AccountNum";

               qc.CriteriaElement[0].DataSourceName = "CustTable";

               qc.CriteriaElement[0].Value1 = "1234";

               EntityKey[] keylist = svc.findKeys(callContext, qc);

               AxdCustomer axdCustomer = svc.read(callContext, keylist);

               //Customer update

               AxdEntity_DirParty_DirPerson PersonNames = (AxdEntity_DirParty_DirPerson)axdCustomer.CustTable[0].DirParty[0];

               PersonNames.PersonName[0].updateMode = AxdEnum_ValidTimeStateUpdate.Correction;

               PersonNames.PersonName[0].updateModeSpecified = true;

               PersonNames.PersonName[0].LastName = "newname";

               svc.update(callContext, keylist, axdCustomer);

           }

  • Community Member Profile Picture
    on at

    For those who are new to AX development, this thread reminded me AIF changes should be made in the AXD classes such as axdcustomer or axdsalestable objects. With this direction, I was able to modify sales order data during AIF imports.

  • Community Member Profile Picture
    on at

    Could you show an example of this?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans