Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

To pass the values from the code to another form

(1) ShareShare
ReportReport
Posted on by 1,457
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
  • Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    To pass the values from the code to another form
    I already gave you a suggestion. Please read the paragraph beginning with "To set the customer account number" in one of the previous replies.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To pass the values from the code to another form
    hi ,
    Everyone , i am really stuck at this , please suggest anything on this .how can i modify the the ok close code to get he value flow from sales order create form .
     
     
    thanks,
    Regards,
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    To pass the values from the code to another form
    Okay, that's how I understood it, just your reply to Layan was wrong.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To pass the values from the code to another form
    hi 
    martin 
    thanks for reply ,
    My button is on sales order create from , i open sales order create form , then click on my button , the dialogue open i create new customer on ok close of dialogue , the newly created customer should pass to sales oedercreate form . this is the process .
     
     
    thanks,
    Regards,
    Dinesh
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    To pass the values from the code to another form
    Dineshkarlekar, you answered "yes" to Layan's question whether your button is in SalesTable form, but your code shows that it's in SalesCreateOrder form. Please clarify it.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To pass the values from the code to another form
    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.
     
  • Layan Jwei Profile Picture
    Layan Jwei 7,379 Super User 2024 Season 2 on at
    To pass the values from the code to another form
    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
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    To pass the values from the code to another form
    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.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To pass the values from the code to another form
    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
  • Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    To pass the values from the code to another form
    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.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans