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

Creating Query object / SysDa API / SQL queries using Json structure

(1) ShareShare
ReportReport
Posted on by 20
Is there anyway we can convert below dynamic json structure to either Query/SysDa object or SQL query using  x++ ? 
 
 
{
            "name": "CustInvoiceJour"
            "select": [
                {
                    "name": "InvoiceID"
                },
                {
                    "name": "InvoiceDate"
                }
            ],
            "fromTable": {
                "name": "CustInvoiceJour"
            },
            "where": [
                {
                    "booleanOperator": "OR",
                    "listOfExpr": [
                        {
                            "booleanOperator": "AND",
                            "listOfExpr": [
                                {
                                    "expr": {
                                        "column": {
                                            "name": "InvoiceID"
                                            
                                        },
                                        "operator": "=",
                                        "value": [
                                                       "1000",
                                                       "2000"
                                                     ]
                                    }
                                },
                                {
                                    "expr": {
                                        "column": {
                                            "name": "InvoiceDate"
                                        },
                                        "operator": "=",
                                        "value": [
                                                       "06/04/2024"
                                                     ]
                                    }
                                }
                            ]
                        },
                        {
                            "expr": {
                                "column": {
                                    "name": "InvoiceID"
                                },
                                "operator": "IN",
                                "value": [
                                                   "1000",
                                                    "2000"
                                             ]
                            }
                        },
                        {
                            "booleanOperator": "AND",
                            "listOfExpr": [
                                {
                                    "expr": {
                                        "column": {
                                            "name": "Voucher"
                                        },
                                        "operator": "NOT IN",
                                        "value": [
                                            "VF11"
                                        ]
                                    }
                                },
                                {
                                    "expr": {
                                        "column": {
                                            "name": "VoucherDate"
                                        },
                                        "operator": "=",
                                         "value": [
                                                       "06/04/2024"
                                                     ]
                                    }
                                }
                            ]
                        }
                    ]
                }
            ],
            "order_by": [
                {
                    "column": {
                        "name": "InvoiceID"
                    },
                    "order": "DESCENDING"
                },
                {
                    "column": {
                        "name": "InvoiceDate"
                    },
                    "order": "DESCENDING"
                }
            ]
        }
 
 
The sql query should be constructed something like below based on the above json via X++:-
 
select invoiceid,invoicedate from custinvoicejour where ((invoiceId in ("1000","2000") 
and invoicedate = '06/04/2024') or invoiceid in ("1000","2000") 
or (voucher not in ("VF11") and voucherDate = "06/04/2024"))
order by invoiceID,invoiceDate desc
 
Also curious if the query can be constructed using SysDa api / Query object in x++.
 
Thanks,
  • Layan Jwei Profile Picture
    7,898 Super User 2025 Season 1 on at
    Creating Query object / SysDa API / SQL queries using Json structure
    Hi,
     
    You said your challenge is with the where condition.
     
    Can you show us what you did so far? And what is not working with you exactly?
  • Martin Dráb Profile Picture
    234,597 Most Valuable Professional on at
    Creating Query object / SysDa API / SQL queries using Json structure
    Choose one of the problem and focus on it. Return to the other later.
     
    If you start with JSON parsing, a good idea may be doing it in a C# library. If you use Paste Special > Paste JSON as Classes, Visual Studio will generate the object model from your JSON for you. Then create a method that accepts the string and returns the root object. Use JsonConvert.DeserializeObject<T>() there to do the deserialization. This will allow you to work with the data in X++ in an object-oriented manner.
  • Indra sena Profile Picture
    20 on at
    Creating Query object / SysDa API / SQL queries using Json structure
    Thanks for the reply martin,
     
    The challenge i am facing is with parsing where clause from Json , and creating the query/query build range.
     
    Also please note that the where clause can grow/shrink by adding adding/removing more filter criteria's.
  • Martin Dráb Profile Picture
    234,597 Most Valuable Professional on at
    Creating Query object / SysDa API / SQL queries using Json structure
    Yes, you can parse the JSON string and create a Query object (or something) based on the data.
     
    If you need more help, please explain what you're struggling with, e.g. if you don't know how to parse JSON, how to create a query in code or if you have a more specific problem.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans