Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

To create new customer using dialog form

Posted on by 1,457
hi every one , 
i want to create new customer using dialog form , i know in account reciavables all customer when we create new a dialog form opens where we create new customer , i want to create same but i need to create only three fields like customer name phone and email. and when i click on ok it create the new customer in all customer, can any one help me on this .
 
Thanks,
Regards,
Dinesh.
  • Martin Dráb Profile Picture
    Martin Dráb 229,963 Most Valuable Professional on at
    To create new customer using dialog form
    Okay, I see. Please help admins to diagnose the problem. Here are their instructions:
    1. go to the forum thread page where the issue occurs -> scroll to the checkbox to be recorded
    2. right-click -> inspect (or F12) -> open developer window to maximum
    3. click the network tab -> on the dropdown menu next to 'invert', select 'XHR and Fetch'
    4. next to the red circle on left side, click the black circle with line through it - this clears the log file
    5. click the 'does this answer your question' checkbox - the network calls populate in the tool
    6. then click the down arrow in the middle of the browser dev tool to download the .har file
    7. attach the .har file to an email and send to DTPDynCommManagers at microsoft.com or dlcommed at microsoft.com
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To create new customer using dialog form
    hi ,
    martin 
    when ever i try to mark to verify the answer , the pages show only loding , it is only allowing me to mark the recent replay , dont now why , i am facing this issue from long time .
     
    thanks,
    Regards,
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 229,963 Most Valuable Professional on at
    To create new customer using dialog form
    Dineshkarlekar, please mark the reply (or replies) that answers the original question, so anyone finding the thread can navigate to the answer. Marking the last reply does not fill in the purpose (if the last reply doesn't happen to be the sole answer). You make this mistake very often, that's why I'm pointing it out.
  • Verified answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    To create new customer using dialog form
    I couldn't understand why you have given a while loop for checking if email or phone number exists and also you are checking with location name. Instead you should have checked with locator directly and also used a single select statement.
     
    As per this thread, you have to create a customer with some contact details. If this requirement is achieved with the answers provided, you can simply mark the helpful answer as verified and create a new thread for your another question.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To create new customer using dialog form
    hi ,
    Thanks for reply ,
     
    I have created the customer  made some changes in code as per martin suggestions , i was getting country region id error so i make it default for now . also applied validation , if someone  pass the email id  or phone and if it already exist in view then the error will triggered . now when i press ok the customer is getting created now i want to pass the newly created customer in SalesCreateOrder form please guide me how can i pass the values on ok click of my dialogue button , my code is below .
    [Form]
    public class DTCreateRetailCustomerForm extends FormRun
    {
        /// <summary>
        ///
        /// </summary>
        public void closeOk()
        {
            super();
            
            CustTable                    custTable;
            NumberSeq                    numberSeq;
            Name                         name = DTCustomerName.valueStr();
     
            DirParty                        dirParty;
            DirPartyPostalAddressView       dirPartyPostalAddressView;
            DirPartyContactInfoView         dirPartyContactInfo,dirPartyContactInfoLoc;
            CustParameters                  custParameters;
            ;
     
            /* Marks the beginning of a transaction.
            Necessary to utilize the method numRefCustAccount() */
            ttsBegin;
            custTable.initValue();
    
            try
            {
                //CustTable
                numberSeq               = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
                custTable.AccountNum    = numberSeq.num();
                
                select CustGroup,DlvMode,TaxGroup from custParameters;
    
                custTable.CustGroup     = CustParameters.CustGroup;
                custTable.DlvMode       = CustParameters.DlvMode;
                custTable.TaxGroup    = CustParameters.TaxGroup;
     
                custTable.insert(DirPartyType::Organization, name);
                custTable.validateWrite();
    
                dirParty = DirParty::constructFromCommon(custTable);
    
                dirPartyPostalAddressView.LocationName      ='';
                dirPartyPostalAddressView.City              ='';
                dirPartyPostalAddressView.Street            ='';
                dirPartyPostalAddressView.StreetNumber      ='';
                dirPartyPostalAddressView.CountryRegionId   ='PAK';
                dirPartyPostalAddressView.State             ='';
                dirPartyPostalAddressView.IsPrimary         = NoYes::Yes;
                // Fill address
                dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
     
                dirPartyContactInfo.LocationName    ='Email Address';
                dirPartyContactInfo.Locator         = DTCustomerEmail.valueStr();
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;
                 
                while select LocationName,Locator from  dirPartyContactInfoLoc
                      where  dirPartyContactInfoLoc.LocationName  == 'Email Address'
                {
                    if(dirPartyContactInfo.Locator == dirPartyContactInfoLoc.Locator)
                    {
                        throw Error('Email already exist');
                    }
                    else
                    {
                        // Fill Contacts
                        dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                    }
    
                }
    
              
    
                dirPartyContactInfo.LocationName    ='Mobile Number';
                dirPartyContactInfo.Locator         = DTCustomerPhone.valueStr();
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;
    
    
    
                while select LocationName,Locator from  dirPartyContactInfoLoc
                      where  dirPartyContactInfoLoc.LocationName  == 'Mobile Number'
                {
                    if(dirPartyContactInfo.Locator == dirPartyContactInfoLoc.Locator)
                    {
                        throw Error('Mobile Number already exist');
                    }
                    else
                    {
                        // Fill Contacts
                        dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                    }
    
                }
     
                // Marks the end of transaction.
                ttsCommit;
            }
          
    
        }
    
    }
    thanks,
    Regards,
    Dinesh
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    To create new customer using dialog form
    Yes Martin, code might be a bit complex compared to entity but this code do create a party. Because if a party is not being provided then in insert() method we have a line of code which creates a party.
     
    Dinesh, to answer your question, it is the same way how you import a customer via standard OOB entity. You just need to call insert at the end of code. You can just try it in runnable class.
     
    But regarding the validation part, as you are just creating customer, then how does a contact already exist for the customer? Or are you saying that that particular email or phone shouldn't exist all together in the base table itself not for particular customer?
     
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To create new customer using dialog form
    hi ,
    Martin ,
    Thanks for reply ,
    I dont know how to create customer using entity in x++ can you please share me any link so i can make changes in my code .
     
     
    thanks ,
    regards,
    Dinesh,
  • Martin Dráb Profile Picture
    Martin Dráb 229,963 Most Valuable Professional on at
    To create new customer using dialog form
    Please try your code. It'll immediately fail, because you ignore what I told you. You can't create a record in CustTable without a party. You also forgot to call and check validateWrite()., Throw away the catch block, because it does nothing useful.
     
    It's a pity that you rejected my suggestions that would be easier and you chose the most difficult way without even understanding the data model. Are you sure that you don't want o change the decision? Let me repeat: Ideally, just use the standard form instead of trying to duplicate the logic. If you insist on doing the same thing in your own code, use the data entity. The entity hides the complexity, therefore it won't be such a big problem that you have no idea about things like DirPartyTable.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To create new customer using dialog form
    hi, 
    everyone , 
    thanks  for reply ,
     i have put the code on the close ok of the dialogue form which create new customer from the dialogue , but i have to just check if email id or phone number already exist in then it should throw error , can you please help me out on this.below is my code.
    [Form]
    public class DTCreateRetailCustomerForm extends FormRun
    {
        /// <summary>
        ///
        /// </summary>
        public void closeOk()
        {
            super();
            
            CustTable                    custTable;
            NumberSeq                    numberSeq;
            Name                         name = DTCustomerName.valueStr();
     
            DirParty                        dirParty;
            DirPartyPostalAddressView       dirPartyPostalAddressView;
            DirPartyContactInfoView         dirPartyContactInfo;
            ;
     
            /* Marks the beginning of a transaction.
            Necessary to utilize the method numRefCustAccount() */
            ttsBegin;
            custTable.initValue();
    
            try
            {
                //CustTable
                numberSeq               = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
                custTable.AccountNum    = numberSeq.num();
                
    
                custTable.CustGroup     = CustParameters::find().CustGroup;
                custTable.DlvMode       = CustParameters::find().DlvMode;
                custTable.PaymTermId    = CustParameters::find().TaxGroup;
                custTable.PaymMode      ='CHEQUE-01';
     
                custTable.insert(DirPartyType::Organization, name);
     
                dirPartyContactInfo.LocationName    ='Email Address';
                dirPartyContactInfo.Locator         = DTCustomerEmail.valueStr();
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;
    
                // Fill Contacts
                dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
    
                dirPartyContactInfo.LocationName    ='Mobile Number';
                dirPartyContactInfo.Locator         = DTCustomerPhone.valueStr();
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;
     
                // Fill Contacts
                dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
     
                // Marks the end of transaction.
                ttsCommit;
            }
            catch(Exception::Error)
            {
                ttsAbort;
                throw Exception::Error;
            }
    
        }
    
    }
     thanks,
    regards,
    dinesh
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    To create new customer using dialog form
    Yes you can call same menuitem from 2 different forms.
     
    But as per this thread, is this issue resolved? If not then let us know where are you still stuck at. If resolved, then mark the answer which helped you and create a new thread for any other issues.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,963 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans