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

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,
I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Indra sena Profile Picture
    20 on at
    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
    237,965 Most Valuable Professional on at
    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.
  • Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    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?

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans