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, ...
Answered

using values coming from multiselect of a dialog

(0) ShareShare
ReportReport
Posted on by 465

Hi,

So i made a batch using sysOperation. The contract has 2 fields. One Named field1 and the other is named field2. These 2 parameters supports multi select.

I made the multiselect using UIBuilder SysLookupMultiSelectGrid::lookup(query,_control,_control,_control,con);

so field1 gets filled like this Invoice1;Invoice2;Invoice3 (with semi colon) same goes for field2.

Now what i want to do is

First i want to 

Table table1;

Table table2;

Select from table1where (table1.flag = no && table1.InvoiceId !=contract.field1)    But how i'm going to get all the values from the contract in field1? and what should i do with semi colon?

then Select from table2 where table2.InvoiceId == contract.field2  Same goes here how to get all selected values contract field 2?

Now Let's say the first select statement returned 10 records and the 2nd one returned 3 records.

I'm trying to export data entity by code so i want to filter the data entity by these 13 records. (Please not this could be more than a thousand so a better approach to what i'm doing would be great).

sysquery::findorcreaterange(qbds, fieldnum(CustInvoiceJour, InvoiceId)).value("");  So here i want to put all the 13 invoices i got back, how to do that?

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

    Your design sounds very complicated in comparison with the usual approach.

    The usual design is using a query and adding ranges for InvoiceId. Users will provide a value of this range (single value, multiple values, wildcards...) and you'll simply execute the query.

    But your code doesn't match your requirement. I think you shouldn't fetch the data by yourself at all (no select from table1/table2) - you should merely pass the query to data management.

  • D365FO user Profile Picture
    465 on at

    Hi Martin,

    Can you please read my last post in this question. There i define my business process exactly. Maybe then you'll be able to help me with the best approach. Thanks alot.

    community.dynamics.com/.../adding-a-new-table-to-an-existing-data-entity

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

    I think I said enough for the topic of "using values coming from multiselect of a dialog". Regarding your other topics, I'll respond in the other thread.

  • D365FO user Profile Picture
    465 on at

    How i'm going to pass the query?

    I want to pass the data entity (custIvoiceJour inner joined with my new table where Flag = False (range))

    but before sending it, i can exclude some of the invoices that have flag = false or i can include some of records that have flag = true.

    from what i know, from the moment i add query range using sysQuery, it means i need to specify every single record. But i don't want to reAdd all invoices with flag = false i want this query to be ready and just add or remove records to it. How can i do that?

    if i did sth like that: this will only give me the container values... but i want the normal result of the data entity in addition to this

    for (i = 1; i <= conLen(con); i  )
    {
          sysquery::findorcreaterange(qbds, fieldnum(CustInvoiceJour, InvoiceId)).value(queryValue(conPeek(con, i)));
    }

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    No, you shouldn't add any ranges for Invoices by yourself - ranges will be specified by users in the dialog and you'll get a Query object containing all those ranges. You said that you "want this query to be ready and just add or remove records to it" and that's exactly what my proposal does.

    Look into your other thread - I gave you a link there showing how to use a query in a SysOperation framework.

  • D365FO user Profile Picture
    465 on at

    Hi Martin,

    ok , but because i'm dealing with entity is this going to make a difference. Let me make things clear and see if i understood u correctly.

    So right now i have a composite entity with header and lines.

    In the header entity, i have custInvoiceJour with New table that is inner joined with custInvoiceJour  and has a range flag = false 

    So currently when the user click the  dialog of the batch process and send directly, it will take the header relation i mentioned above and give me all invoices inner joined with my new table with flag = false. Below is the code in the service class

    EntityName      entityName;
                DMFEntity       dmfEntity;
    
    
                select firstonly dmfEntity  order by EntityName asc where dmfEntity.TargetEntity == dataEntityViewStr(AASalesInvoiceV2Composite);
    
                entityName = dmfEntity.EntityName;
    
                Query                query = new Query(DMFUtil::getDefaultQueryForEntity(entityName, "ExportTest"));
                
                str x = "#FieldGroupName_AllFields";
                DMFEntityExporter exporter = new DMFEntityExporter();
                fileId = exporter.exportToFile(entityName,
                                    definitionGroupName,
                                    '', //Optional: ExecutionID
                                    "XML-Element", //Optional::SourceName
                                    x, //Optional field selection
                                    query.pack(), //Optional: Filtered Query
                                    curExt() //Optional: DataAReaId
                                    );
                                    
                if (fileId != '')
                {
                    str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(fileId));
    
                    System.Uri uri = new System.Uri(downloadUrl);
                    str fileExt;
    
                    if (uri != null)
                    {
                        fileExt = System.IO.Path::GetExtension(uri.LocalPath);
                    }
    
                    Filename filename = strFmt('Export%1',fileExt);
                    System.IO.Stream stream = File::UseFileFromURL(downloadUrl);
                    File::SendFileToUser(stream, filename);
                }

    Now i do want the result of this query. So let's say this result give me 10 invoices.

    But the user has the option to remove some of these 10 invoices before sending. Or he has the option to add invoices outside this result and by that i mean ( my new table inner joind custInvoiceJour with flag = true)

    Now what you're saying is, maybe i should create two queries, one with flag = false and one with flag = true and add them to my contract class?  and by doing that i will be able to get two InvoiceId fields one to exclude and one to include

    But i still don't get it, how i'm going to say in the service class, that take the original result of the data entity and exclude and include what the user put in the dialog? can u explain more how i'm going to do it.

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

    If the user should be able to add records that the query doesn't return, than you have a wrong query. You'll have to rethink that.

    I don't know your business scenario, which is absolutely critical to do a good design. So I can't do it; I can only give you some ideas without knowing if they're reasonable. You'd have to explain your business scenario to allow us to really help you with the design.

    For example, think about the use case of removing invoices from those ten returned by the query. With your current design, users don't know what the query returns. They could ran the query somewhere else (such as filtering a form), identify invoice IDs that they want to exclude, copy them one by one and put them into your dialog. Is it really good user experience? Maybe you should rather run the query, put the result into a grid and allow users to delete or uncheck records that they don't want.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi D365FO_user,

    There is also option to mark invoices on the form and pass this list to action class. In this case users can use standard filter options on the form itself.

    community.dynamics.com/.../multi-select-on-form-datasource-grid-multiselectionhelper

  • D365FO user Profile Picture
    465 on at

    Hi Martin,

    Here's the business scenario.

    Once the invoices are posted... These invoices gets filled in my new table with flag = false

    The user would like to send all those that has flag = false with the option to exclude some the has flag = false or include ones that has flag = true. If he didn't specify anything on the dialog it will send all invoices with flag = false.

    When i click send, it should use the data entity that has my table inner joined to custInvoiceJour.. Generate a file and send it to azure blob.

    My data entity had a range with flag =false

    that's why i wanted to include two parameters one that shows all with flag = false to exclude and one that shows flag = true to include

    so in the drop down of exclude he is really seeing all those that has flag = false so he already know what will be sent except the ones he'll choose 

    And inside the service maybe i'll take those selected and switch their flag to 0 or 1 based if i want to include or exclude just to match the range of data entity and after generating the file i will return them to their original flag value...

    Is there a better way to do it? And how to do it with query filter instead? And what should i do to my data entity range?

    And if we just look at the excluded ones... How i'm going to say in the service class take all the ones that has flag = flase except the ones specified in the dialog to exclude? From a technical point of view? 

    Same goes to the ones to include? 

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

    You're describing again your technical design, not a business scenario. Things like boolean fields, inner joins and so on are mere implementation details. A design must start with business requirements and not with implementation details.

    How we could tell if your design is good for your business requirements or there is a better one, if we don't know these requirements?

    There are three options for us:

    • We can try to improve little details of your implementation, although the whole design may be completely wrong.
    • We can urge you to think about the design and give you some suggestions, as I did.
    • Or we need to get all details from you so we can review how your design matches the requirements and possibly propose a better solution for the same business requirements.

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 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans