Pages

Monday, May 11, 2015

How to create/update a phone number for a customer/vendor in X++ [AX 2012]

As a follow-up to my last post about finding phone numbers, here is sample code of how you can properly find/create/update a phone number for a customer/vendor.


static void CreatePhoneExample(Args _args)
{
    CustTable                           custTable = CustTable::find('100013'); // TODO - Change to your customer
    LogisticsElectronicAddress          logisticsElectronicAddress;
    container                           defaultRole = map2Con(LogisticsLocationEntity::getDefaultLocationRoleFromEntity(tableNum(DirPartyTable)));
    
    setPrefix(strFmt("Creating/Updating number for customer %1", custTable.AccountNum));
    
    // This will find/create a number for a customer
    ttsBegin;
    logisticsElectronicAddress.Type = LogisticsElectronicAddressMethodType::Phone;
    logisticsElectronicAddress.Locator = '555-555-5555';
    
    logisticsElectronicAddress.Location = DirPartyLocation::findOrCreate(custTable.Party, 0).Location;

    // This will find or create the new logisticsElectronicAddress
    // If it does not find it, it will do a .insert() which will only persist these fields (Location, Type, Locator, LocatorExtension)
    // so if you want to set the Description or if it's primary or not, you will need to update the record after this call
    logisticsElectronicAddress = LogisticsElectronicAddress::findOrCreate(logisticsElectronicAddress);
    
    // We re-select it for update in case this isn't a new number and it found an existing
    // because the "find" doesn't "select for update"
    logisticsElectronicAddress = LogisticsElectronicAddress::findRecId(logisticsElectronicAddress.RecId, true);
    
    logisticsElectronicAddress.Description = "New Primary Phone";
    
    // If you set the number to primary, during the insert/update it will handle unassigning previously
    // marked primary numbers if they exist
    logisticsElectronicAddress.IsPrimary = NoYes::Yes;
    
    logisticsElectronicAddress.update();
    
    // At this point, we need to mark the "purpose" of the number.  I'm just using the default role, which should be "Business"
    LogisticsEntityLocationRoleMap::createEntityLocationRoles(tableNum(LogisticsElectronicAddressRole), logisticsElectronicAddress.RecId, conPeek(defaultRole, 1), true);
    
    info(strFmt("Created/updated phone number [%1] for customer %2.", logisticsElectronicAddress.Locator, custTable.AccountNum));
    ttsCommit;
}

45 comments:

  1. In my case it's not updating an existing entry, is creating a new.

    ReplyDelete
  2. Hello Alex,
    container defaultRole map2Con(LogisticsLocationEntity::getDefaultLocationRoleFromEntity(tableNum(DirPartyTable)));
    How can get "Invoice Email" role in the purpose instead of defaultRole i.e. Business
    Kindly advice
    Thanks,
    shankar :)

    ReplyDelete
  3. his is the exceptional component for the customer. It is exceptionally cutting-edge framework and that organization all inclusive instant to customers for phone number deciphering service.how expensive is a 0800 line?

    ReplyDelete
  4. Complete selection of telephone jack adapters are now being offered by retailers, compatible to your laptop and modem, for your worldwide travel. free business calls

    ReplyDelete
  5. This is quite a new free SMS service, online in 2010 I think. It's free for india users only but you can send cheap SMS to other parts of the world if you buy credits bestmobilenumbertracker.com/free-sms

    ReplyDelete
  6. A regular phone directory is basically used to obtain the phone number of a certain individual through the use of his or her name or address while a reverse cell phone lookup service works the other way around. this contact form

    ReplyDelete
  7. Sooner or later, you will probably need to utilize a turn around phone number look into; more often than not, individuals utilize this support of discover name from phone number, if the show on their phone does not demonstrate who is calling. free-lookup.net

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Worked perfectly. Thanks for this man.

    ReplyDelete
  10. This is not just a mere piece of work. This is ART.
    yahoo finance

    ReplyDelete
  11. In the event that you are US national then you don't have to stress at all as there are a lot of online administrations that will give you tracking administrations to GPRS actuated PDAs. localiser un portable gratuitement grace a son numero

    ReplyDelete
  12. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! For more info click here about telephone number search...

    ReplyDelete
  13. He is confident to the point that his arrangements and recommendations will accumulate constructive reaction and trust among the organization's key people.https://www.techpally.com/caller-name-announcer/

    ReplyDelete
  14. Superb examining .Thanks for sharing. It's late finding this show up. https://callgear.com/product/calls-tag/

    ReplyDelete
  15. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. Sony Xperia cases

    ReplyDelete
  16. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also https://locateanumber.com

    ReplyDelete
  17. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. legal entity identifier

    ReplyDelete
  18. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. https://www.phonenumber-track.com

    ReplyDelete
  19. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! Onida Customer Care

    ReplyDelete
  20. If you would like expand your cell phone's local capabilities, there isn't any better method so than to examine location-based iPhone apps! click this link

    ReplyDelete
  21. The post is written in very a good manner and it contains many useful information for me. How to spy a phone

    ReplyDelete
  22. A vital source for the audience that takes the reader step by step.
    spy phone app

    ReplyDelete
  23. That is really nice to hear. thank you for the update and good luck. spy phone

    ReplyDelete
  24. At the point when you take a gander at iPhone screen substitution you might be hoping to burn through $30 to $130 contingent upon the arrangement you pick. In the event that you decide to supplant your screen yourself, you can buy them off of the web for around $30.Display Iphone reparatur

    ReplyDelete
  25. If more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content. iPhone 12 Screen protector

    ReplyDelete
  26. Building an Access information base typically begins with chipping away at the tables first and getting the right sorts of informational index in your application from the beginning saving you a ton of time and cerebral pains later when computing and alluding to numeric qualities somewhere else.Numbers

    ReplyDelete
  27. A decent cover will have the option to limit the harm incurred on it. iphone 11 pro max

    ReplyDelete
  28. A straightforward output of accessible advanced cells from any significant transporter will as a rule feature phones in pretty much every shade of the rainbow. buy iphone 12

    ReplyDelete
  29. Molte persone vedono che devi eseguire un preciso gioco di gambe prima di scrivere. Può essere concepibile per aiutarti a un articolo molto più piacevole come questo. app per bloccare le chiamate

    ReplyDelete
  30. Become a more effective seller online. Check out this guide to the 15 most common terms used in reference to cheap phones and how you should use them. 꽁짜폰

    ReplyDelete
  31. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. https://localisertel.com

    ReplyDelete
  32. Hi there! Nice post! Please tell us when I will see a follow up! cell phone tracker

    ReplyDelete
  33. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. cow phone case

    ReplyDelete
  34. I read your blog frequently and I just thought I’d say keep up the amazing work! hoverwatch review

    ReplyDelete
  35. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. download phone tracker

    ReplyDelete
  36. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks iPhone deals

    ReplyDelete
  37. Make a rundown of that multitude of telephone extras that are popular and contact your provider. phone case manufacturers

    ReplyDelete
  38. Phone cases protect your DIY cell phone case from getting damaged. Do you have a phone and would like to protect it? Here are some of the best cases that you should go for: Pouches and Sleeves These cases completely encase your phone in order to protect it from scratches. In addition to this they also provide you with extra padding that protects your device against bumps, drops and shocks. While they are great in protecting your phone, they usually limit access to the phone's touch screen; therefore, if you want to access the features you have to pull your phone from the case.

    ReplyDelete
  39. This comment has been removed by the author.

    ReplyDelete
  40. This comment has been removed by the author.

    ReplyDelete
  41. Absolutely fantastic post! I'm thoroughly impressed by its usefulness and quality. It's truly exceptional and captivating. I'm sincerely hoping you keep up this remarkable work in the future as well. https://rastrearimei.com

    ReplyDelete