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)

Job to change customer partyType

(0) ShareShare
ReportReport
Posted on by 755

I have roughly 16,000 customers inserting into DAX with the incorrect partyType. I want to change customers with type person to organization and thanks to Andre from Kaya I have this job that will change one record.

static void changeCustomerPartyAssociation(Args _args)
{

DirPartyEntityAssociationUpdate entityAssociation;
DirPartyMap entityRecord;
DirPartyTable firstParty, associatedParty;
CustTable custTable;
CustAccount custAccount;

custAccount = "00000641";

custTable = custTable::find(custAccount, true);
entityRecord = custTable;

entityAssociation = new DirPartyEntityAssociationUpdate();
entityAssociation.setEntityRecord(entityRecord);

// setting original party
firstParty = DirPartyTable::findRec(entityAssociation.getParty());

// creating new party (type Organization)
associatedParty = DirPartyTable::createNew(DirPartyType::Organization, custTable.name());

// setting new party
entityAssociation.setNewParty(associatedParty.RecId);
entityAssociation.run();
}

This works, but I'd like to read a CSV of accounts that need changing and run this code for each of the 16,000. I think that the code below somehow applied to the code above could work, but I'm still somewhat new to x++ and am not sure how to meld the two jobs together.

static void TestCommaTextIO(Args _args)
{
    #File
    CommaTextIo        commaTextIo;
    FileIOPermission   permission;
    container          containFromRead;
    int                x;
    int                cols;
    ;
    permission = new FileIOPermission('c:\\junk\\mycsv.csv',#io_read);
    permission.assert();

    commaTextIo = new CommaTextIO('c:\\junk\\mycsv.csv','R');

    containFromRead = commaTextIo.read();
    While(containFromRead)
    {
        cols = conLen(containFromRead);
        for(x=1;x<=cols;x++)
        {
            print conpeek(containFromRead,x);
        }
        containFromRead = commaTextIo.read();
    }
    pause;
    commaTextIo = null;
}



Any help would be appreciated

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,183 Super User 2025 Season 2 on at

    Hi Russ,

    Can you tell more about the format of the file? Does it contain only one column?

  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,183 Super User 2025 Season 2 on at

    Hi Russ,

    Assuming the customer account is always in the first column, try this:

    static void MassUpdateCustAssociation(Args _args)
    {
        #File
        CommaTextIo        commaTextIo;
        FileIOPermission   permission;
        container          containFromRead;
        int                x;
        int                cols;
    
        DirPartyEntityAssociationUpdate entityAssociation;
        DirPartyMap                     entityRecord;
        DirPartyTable                   firstParty, associatedParty;
        CustTable                       custTable;
        CustAccount                     custAccount;
    
        ;
        permission = new FileIOPermission('c:\\junk\\mycsv.csv',#io_read);
        permission.assert();
    
        commaTextIo = new CommaTextIO('c:\\junk\\mycsv.csv','R');
    
        containFromRead = commaTextIo.read();
        While(containFromRead)
        {
            custAccount = conpeek(containFromRead,1);
     custAccount = "00000641";
    
     custTable = custTable::find(custAccount, true);
      entityRecord = custTable;
    
     entityAssociation = new DirPartyEntityAssociationUpdate();
      entityAssociation.setEntityRecord(entityRecord);
    
     // setting original party
      firstParty = DirPartyTable::findRec(entityAssociation.getParty());
    
     // creating new party (type Organization)
      associatedParty = DirPartyTable::createNew(DirPartyType::Organization, custTable.name());
    
     // setting new party
      entityAssociation.setNewParty(associatedParty.RecId);
      entityAssociation.run();
    
            containFromRead = commaTextIo.read();
        }
        commaTextIo = null;
    
        info("Job finished");
    }


    I have merged it using Notepad as I don't have access to an appropriate AX environment at this moment.

    So please try to compile and run it first with a smaller file to test it.

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans