AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.12.2018, 17:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: “in” operator in D365FO
Источник: http://dev.goshoom.net/en/2018/12/in...tor-in-d365fo/
==============

Yesterday Michael Fruergaard Pontoppidan published a brief blog post New capability in X++ : The In operator. He mentioned that this feature went unnoticed by most, which is my case too. And I didn’t find anything even when I explicitly looked for more information.

Anyway, such an operator can be very handy and I’m quite sure that everybody who knows IN() operator in T-SQL sometimes missed it in X++.

In short, it allows you to check if a field value is in a set of expected values. For example, if I want to find all sales orders with status either Delivered or Invoice, I can do this:

SalesTable st;container statuses = [SalesStatus::Delivered, SalesStatus::Invoiced]; select from st where st.SalesStatus in statuses;






The generated code is what you had to do when there was no ‘in’ operator – it uses OR:

SELECT * FROM SALESTABLE T1 WHERE (((PARTITION=123) AND (DATAAREAID=N'dat')) AND ((SALESSTATUS=3) OR (SALESSTATUS=2)))






I wanted to know what else I can do with this operator and because I didn’t find any documentation, I tried a few things by myself. Note that my environment has platform update 20; it might behave differently in different versions.

I wondered if I can’t use a container directly, instead of putting it to a variable. It would make things simpler if the set is known at design time.

select count(RecId) from st where st.SalesStatus in [SalesStatus::Delivered, SalesStatus::Invoiced];






The editor didn’t show any error, but compilation blew up completely:

Abnormal termination with unhandled exception. Exception key: a59d89f7-fe80-4ab3-a420-9a6ba9a30bca. System.NullReferenceException: Object reference not set to an instance of an object.

Hmm, let’s try something else. Which data types can I use? What about a set of string values, which is a common scenario?

container ids = ["S01", "S02", "S03"]; select st where st.SalesId in ids;






This fails already in the editor. The compilation error is: Types ‘str’ and ‘container’ are not compatible with operator ‘in’.

The last thing I tried was using ‘in’ operator outside a query. I didn’t expect it to work and it indeed doesn’t. This doesn’t compile; it fails with ‘)’ expected.

if (highestStatus in statuses)






The ‘in’ operator is useful and I’m glad it’s been added. But I see space for improvement, especially the ability of using it with string fields would be very useful.



Источник: http://dev.goshoom.net/en/2018/12/in...tor-in-d365fo/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
goshoom: Throwing managed exceptions from X++ in D365FO Blog bot DAX Blogs 0 30.10.2018 14:11
goshoom: Find D365FO labels in Powershell Blog bot DAX Blogs 0 28.10.2018 17:11
goshoom: Printing reports from code in D365FO Blog bot DAX Blogs 0 12.10.2018 15:11
goshoom: Code snippets in AX 7 – The Problem Blog bot DAX Blogs 0 30.06.2016 12:11
goshoom: Preview of Release Management Blog bot DAX Blogs 0 15.10.2015 12:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 14:33.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.