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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

To pass the values from the code to another form

(1) ShareShare
ReportReport
Posted on by 1,836
hi
everyone ,
 i was trying to pass the current records which are getting created from my code to other form at the click of ok button on form ,
can anyone plz help me with code as i tried to get values in args but i was getting error that args cannot be mension here use this instead.please  help me out on this .
below is my code .
 
Thanks,
regards,
Dinesh
  • Dineshkarlekar Profile Picture
    1,836 on at
     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
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Can you elaborate please?
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    thanks for reply ,
     
    New customer is geting created here , when i press ok so at same time i want to pass the customer to "salescreateOrder " form , can you help me on this , i tried with args butt it gives me error that args  is not supported here. 
     
    Thanks ,
    Regards,
    Dinesh
  • Komi Siabi Profile Picture
    13,253 Most Valuable Professional on at
    You are creating a new customer yourself instead of using the standard customer form. Why is that so ? 
    And where are you calling your code from ? Please explain better. 
     
    Do you have a customer form to create customers, or is done via a endpoint ?
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi ,
    I have created dialogue form , which is call by button on another form which close ok button creates a customer for another form , now i need to pass the newly created customer to the form on which the button apens the dialogue ,can you help me on this, please.
     
    thanks,
    Regards,
    Dinesh 
  • Martin Dráb Profile Picture
    241,655 Most Valuable Professional on at
    The code you showed us is not relevant to your current question, while you told us very little about the actual topic.

    Please start by explaining the business scenario. Do you mean that after creating the customer, you want to automatically populate the customer account field in the sales order creation dialog?

    How are calling the form? Do you open through a menu item button? Or should it be a RunBase/SysOperation dialog? Or it there some other logic involved?

    Do you need a form at all? Can't you simply define a data contract and get the form generated for you?

    Regarding "i tried with args butt it gives me error that args  is not supported here", do you believe that this tells us what code you wrote and where you got the error? It does not. You'll need to do a better job describing your problem if you really want to get a solution from us.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    Martin , 
    thanks for reply ,
     
     "Do you mean that after creating the customer, you want to automatically populate the customer account field in the sales order creation dialog?"
    yes i want to do the same , and i am calling the dialogue using this code , 
     /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormControlEventHandler(formControlStr(SalesCreateOrder, DTCreateCustomer), FormControlEventType::Clicked)]
        public static void DTCreateCustomer_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            Args args = new Args();
            Form formToCall = new Form('DTCreateCustomerForm');
    
            FormButtonControl callerButton = sender as FormButtonControl;  //Retrieves the button that we're reacting to
            FormRun form = callerButton.formRun(); //Gets the running SalesCreateOrder form
    
            //Get the SalesCreateOrder that was selected in the SalesCreateOrder form
            FormDataSource SalesTable_ds = form.dataSource(formDataSourceStr(SalesCreateOrder, SalesTable)) as FormDataSource;
            SalesTable salesTable  = SalesTable_ds.cursor();
    
            //Set up args with all of the information you've retrieved
            args.caller(form);
            args.object(formToCall );
            //args.record(hcmWorker);
    
            form = ClassFactory.formRunClass(args);
            form.init();
            form.run();
            form.wait();
    
        }
    after the dialogue opens i fill customer details and the , code on ok close runs , and new customer gets created so  i will be passing the new customer to sales order create form .it is working till customer creation but not able to pass cuatomer to sales order creation form .
     
    thanks,
    regards,
    Dinesh
  • Suggested answer
    Martin Dráb Profile Picture
    241,655 Most Valuable Professional on at
    You said you wanted a dialog, but this looks like a normal form. Anyway, you again made things more complicated than necessary, because you can open the form without a single line of code. Throw your code away and create a menu item button for your form. Then drag this menu item to SalesCreateOrder form, which will create a menu item button for you. You'll get what you tried with your code, plus a few benefits such as reusability of the menu item, less code to maintain, easier security setup etc.
     
    To set the customer account number, notice that the form control is bound to a data source field (SalesTable.CustAccount). Therefore you can pass a table buffer of SalesTable data source to your form and set the field value there. When you use the menu item as explained above, the active SalesTable record should be passed automatically. If not, set the Data Source property on the menu item button to SalesTable.
     
    In your form, this.args().record() will give you the SalesTable record.
  • Layan Jwei Profile Picture
    8,428 Super User 2026 Season 2 on at
    Hi Dinesh,
     
    Just trying to understand what you are doing here.
    Did you create a button called create customer on the salesTable form? And once you click this button, the dialog to fill customer details opens, where you fill the data, then click ok. And once you click ok, you want the sales order creation form to open? Where the custAccount chosen in the first dialog needs to be passed to the 2nd dialog?
     
     
    And when you say "but not able to pass customer to sales order creation form" do you mean that the sales order form opens correctly with you after the first dialog, but with empty custAccount?
     
    Thanks,
    Layan Jweihan
     
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi , 
    lyan , thanks for reply ,
     
    yes after filling the customer i will pass the value from dialog to sales order create form . so i need to get the sales order create form and then i will be able to pass values in sales order create form .
     
    thanks,
    Regards,
    Dinesh.
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 266 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 217

#3
Subra Profile Picture

Subra 164 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans