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 :
Finance | Project Operations, Human Resources, ...
Unanswered

How to get selected records

(0) ShareShare
ReportReport
Posted on by 148

pastedimage1672227726667v1.png

consider above image. How to get marked records. below is my code but only last selected record I'm getting.

[FormControlEventHandler(formControlStr(SalesCopying, OK), FormControlEventType::Clicked)]
public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
{
SalesTable salesTable;
FormRun formRun = sender.formRun() as FormRun;
FormDataSource salesTable_ds;
FormDataSource salesLine_ds;
SalesLine line;

salesTable_ds = sender.formRun().dataSource(1);
salesTable = salesTable_ds.cursor();
salesLine_ds = formRun.dataSource(2);

MultiSelectionHelper helper = MultiSelectionHelper::construct();
helper.parmDatasource(salesLine_ds);
line = helper.getFirst();

while (line.recid != 0)
{
   info(strFmt("%1",line.ItemId));
   line = helper.getNext();
}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Which record do you expect to get? You're using MultiSelectionHelper to get all selected sales order lines, but you have only one selected, therefore getting one is the right result.

  • Prasanth Profile Picture
    148 on at

    Thanki you for responding Martin.

    If I select 3 lines in Lines like above image but I'm getting only last record.

    any issues in my code ??

  • Prasanth Profile Picture
    148 on at

    pastedimage1672229741282v1.png

    Here I selected 2 records but I'm getting only one.

    Please advise.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Why did you ask us to consider the the image if you're now saying that it doesn't show your actual scenario? Or do you believe that you can select lines from different orders (which isn't possible)?

    How do you test what you get? What exactly do you see when you debug your code?

    By the way, let me throw away unused code and post your method in the right way:

    [FormControlEventHandler(formControlStr(SalesCopying, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
    	FormRun formRun = sender.formRun() as FormRun;
    	FormDataSource salesLine_ds = formRun.dataSource(2);
    
    	MultiSelectionHelper helper = MultiSelectionHelper::construct();
    	helper.parmDatasource(salesLine_ds);
    	SalesLine line = helper.getFirst();
    
    	while (line.RecId != 0)
    	{
    		info(line.ItemId);
    		line = helper.getNext();
    	}
    }

  • Prasanth Profile Picture
    148 on at

    my requirement is if SO1 contains 10 lines out of 10, 5 are picked and 5 are non -picked. if we are copying lines to SO2 from SO1. only non - picked line should be copy if user selects any one of picked lines need to throw an error. if user selects no picked line lines should be copied to SO2 from SO1 and copied lines should be deleted in SO1 once copied to SO2.

    My actual code is :

       [FormControlEventHandler(formControlStr(SalesCopying, OK), FormControlEventType::Clicked)]
        public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            SalesTable              salesTable;
            FormRun                 formRun = sender.formRun() as FormRun;
            FormDataSource          salesTable_ds;
            FormDataSource          salesLine_ds;
            SalesLine               salesLine;
            WHSLoadLine             WHSLoadLine,loadLine;
            boolean                 status;
    
            salesTable_ds = sender.formRun().dataSource(1);
            salesTable    = salesTable_ds.cursor();
            salesLine_ds  = formRun.dataSource(2);
            //line          = salesLine_ds.cursor();
            status        = false;
    
            while select * from salesLine where salesLine.SalesId == salesTable.SalesId 
                && (SalesTable.ApntSalesGroupId == "EOC" || SalesTable.ApntSalesGroupId == "EOF" || SalesTable.ApntSalesGroupId == "EOO")
                join WHSLoadLine where WHSLoadLine.OrderNum == salesLine.SalesId  && WHSLoadLine.PickedQty > 0 //&& WHSLoadLine.ItemId == salesLine.ItemId
            {
                throw error("You cannot copy picked lines");
                return;
            }
            
            formRun.closeOk();
            status = true;
    
            if(status == true)
            {
                ttsbegin;
    
                
                SalesLine line;
                MultiSelectionHelper helper = MultiSelectionHelper::construct();
                helper.parmDatasource(salesLine_ds);
                line = helper.getFirst();
       
                while (line)
                {
                    if(line.whsGetLoads() == "" && line.SalesId == salesTable.SalesId && (SalesTable.ApntSalesGroupId == "EOC" || SalesTable.ApntSalesGroupId == "EOF" || SalesTable.ApntSalesGroupId == "EOO"))
                    {
                        //line.selectForUpdate(true);
                        //line.delete();
                    }
                    info(strFmt("%1",line.ItemId));
                    line = helper.getNext();
                }
    
    
                //    //formHasMethod(formRun, formMethodStr(SalesCopying, editCopy))
                //while select forupdate salesLine where salesLine.SalesId == salesTable.SalesId 
                //    && (SalesTable.ApntSalesGroupId == "EOC" || SalesTable.ApntSalesGroupId == "EOF" || SalesTable.ApntSalesGroupId == "EOO")
                //    && salesLine.whsGetLoads() == "" && formRun.copy() == NoYes::Yes;
                //   // join WHSLoadLine where WHSLoadLine.OrderNum == salesLine.SalesId  && WHSLoadLine.PickedQty <= 0  //&& WHSLoadLine.ItemId == salesLine.ItemId
                //   if(salesLine)
                //    {
                //        salesLine.delete();
                //    }
                ttscommit;
            }
        }

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I'm sorry, but it does seem to answer my questions. And adding more irrelevant code to the discussion doesn't make sense. You surely won't get complex code working if you can't do it with a simple piece.

    Please use the simplified code and debug it to see what's going on.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Note that selecting a record in the grid and changing the value of the Select field are two different things.

  • Prasanth Profile Picture
    148 on at

    if SO1 contains 10 lines out of 10, 5 are picked and 5 are non -picked. if we are copying lines to SO2 from SO1. only non - picked line should be copy if user selects any one of picked lines need to throw an error. if user selects non picked line, lines should be copied to SO2 from SO1 and copied lines should be deleted (only non picked lines) in SO1 once copied to SO2.

    Above is my scenario. I'm unable to achieve that scenario. Any suggestions please.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I'm sorry, but a description of a business requirement doesn't allow me to find bugs in your implementation. That's a completely different thing. Instead, you would need to provide more information about your implementation.

    For example, you didn't even tell us what you mean by selecting a record. As I mentioned, it's possible that you want to use your "Select" field, but you don't use it in your code. MultiSelectionHelper has nothing to do with with such a field.

    Unfortunutely you still didn't give us any information about it and you keep repreating something about picked lines, which is not relevant to this problem. It'll be your next, but you can't do a next step if you don't do the first.

  • Prasanth Profile Picture
    148 on at

    while select forupdate salesLine where salesLine.SalesId == salesTable.SalesId 
                    && (SalesTable.ApntSalesGroupId == "EOC" || SalesTable.ApntSalesGroupId == "EOF" || SalesTable.ApntSalesGroupId == "EOO")
                    && salesLine.whsGetLoads() == "" && formRun.copy() == NoYes::Yes;
                   // join WHSLoadLine where WHSLoadLine.OrderNum == salesLine.SalesId  && WHSLoadLine.PickedQty <= 0  //&& WHSLoadLine.ItemId == salesLine.ItemId
                   if(salesLine)
                    {
                        salesLine.delete();
                    }

    Let us assume SO1 contains 500 lines.

    user only 200 lines selected. those selected lines only we need copy to new sales order(SO2) and those copied lines we need to delete in old sales order(SO1) . Addition to this any one of the line is picked in those 200 lines we need to throw error like "you cannot copy picked line"

    in that "select " is display method I tried but I'm unable to found a way how to use that display method.

    FormRun.copy() is nothing but "Select" field ( It's a form display method )

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans