首页 > 其他分享 >refresh、reread、research and executeQuery

refresh、reread、research and executeQuery

时间:2023-08-08 14:11:55浏览次数:44  
标签:reread form executeQuery refresh research will formDataSource query

X++ developers seem to be having a lot of trouble with these 4 datasource methods, no matter how senior they are in AX.
So I decided to make a small hands-on tutorial, demonstrating the common usage scenario for each of the methods. I have ordered the methods based on the impact on the rows being displayed in the grid.

1. Common mistakes

Often, developers call 2 of the mentioned methods in the following order:
formDataSource.refresh()
formDataSource.research()
or
formDataSource.reread()
formDataSource.research()
or
formDataSource.research()
formDataSource.executeQuery()
or
formDataSource.research()
formDataSource.refresh() / formDataSource.reread()
All of these are wrong, or at least partially redundant.
Hopefully, after reading the full post, there will be no questions as to why they are wrong. Leave a comment to this post if one of them is still unclear, and I will try to explain in more detail.

2. Refresh

This method basically refreshes the data displayed in the form controls with whatever is stored in the form cache for that particular datasource record. Calling refresh() method will NOT reread the record from the database. So if changes happened to the record in another process, these will not be shown after executing refresh().

refreshEx

Does a redraw of the grid rows, depending on the optional argment for specifying the number of the record to refresh (and this means the actual row number in the grid, which is less useful for AX devs). Special argument values include -1, which means that all records will be redrawn, and -2, which redraws all marked records and records with displayOptions. Default argument value is -2.
This method should be used sparingly, in cases where multiple rows from the grid are updated, resulting in changes in their displayOptions, as an example. So you should avoid using it as a replacement for refresh(), since they actually have completely different implementations in the kernel.
Also, note, that refreshEx() only redraws the grid, so the controls not in the grid might still contain outdated values.Refresh() updates everything, since this is its intention.

3. Reread

Calling reread() will query the database and re-read the current record contents into the datasource form cache. This will not display the changes on the form until a redraw of the grid contents happens (for example, when you navigate away from the row or re-open the form).
You should not use it to refresh the form data if you have through code added or removed records. For this, you would use a different method described below.

How are these 2 methods commonly used?
Usually, when you change some values in the current record through some code (for example, when the user clicks on a button), and update the database by calling update method on the table buffer, you would want to show the user the changes that happened.
In this case, you would call reread() method to update the datasource form cache with the values from the database (this will not update the screen), and then call refresh() to actually redraw the grid and show the changes to the user.

Clicking buttons with SaveRecord == Yes
Each button has a property SaveRecord, which is by default set to Yes. Whenever you click a button, the changes you have done in the current record are saved to the database. So calling reread will not restore the original record values, as some expect. If that is the user expectation, you as a developer should set the property to No.

4. Research

Calling research() will rerun the existing form query against the database, therefore updating the list with new/removed records as well as updating all existing rows. This will honor any existing filters and sorting on the form, that were set by the user.

Research(true)

The research method starting with AX 2009 accepts an optional boolean argument _retainPosition. If you callresearch(true), the cursor position in the grid will be preserved after the data has been refreshed. This is an extremely useful addition, which solves most of the problems with cursor positioning (findRecord method is the alternative, but this method is very slow).

5. ExecuteQuery

Calling executeQuery() will also rerun the query and update/add/delete the rows in the grid. The difference in behavior from research is described below.
ExecuteQuery should be used if you have modified the query in your code and need to refresh the form to display the data based on the updated query.

formDataSource.queryRun().query() vs formDataSource.query()
An important thing to mention here is that the form has 2 instances of the query object – one is the original datasource query (stored in formDataSource.query()), and the other is the currently used query with any user filters applied (stored in formDataSource.queryRun().query()).
When the research method is called, a new instance of the queryRun is created, using theformDataSource.queryRun().query() as the basis. Therefore, if the user has set up some filters on the displayed data, those will be preserved.
This is useful, for example, when multiple users work with a certain form, each user has his own filters set up for displaying only relevant data, and rows get inserted into the underlying table externally (for example, through AIF).
Calling executeQuery, on the other hand, will use the original query as the basis, therefore removing any user filters.
This is a distinction that everyone should understand when using research/executeQuery methods in order to prevent possible collisions with the user filters when updating the query.

标签:reread,form,executeQuery,refresh,research,will,formDataSource,query
From: https://www.cnblogs.com/yaoweisblog/p/17613965.html

相关文章

  • Statement.executeQuery() cannot issue statements that do not produce result sets
    在用SpringBootJPA的时候导致Statement.executeQuery()cannotissuestatementsthatdonotproduceresultsets解决方法:在@Query上加上@Modifying,表示不需要返回值@Query对应到底层jdbc框架是Statement.executeQuery(),而@Modifying@Query对应的是Statement.execute();......
  • JDBC preparedStatement.executeQuery() 与 preparedStatement.executeQuery(sql)
    preparedStatement.executeQuery()这个方法是执行带占位符、已经预编译的sql命令而它--->preparedStatement.executeQuery(sql)这个方法是执行未预编译、完整的sql命令,而不是预编译的sql命令preparedStatement不是应该执行预编译的sql吗?是这样的,但是preparedStatement还兼......
  • Spring的refresh()方法相关异常
    如果是经常使用Spring,特别有自己新建ApplicationContext对象的经历的人,肯定见过这么几条异常消息:1.LifecycleProcessornotinitialized-call'refresh'beforeinvokinglifecyclemethodsviathecontext:......2.BeanFactorynotinitializedoralreadyclosed-call'ref......
  • SpringBoot源码第三章-refreshContext
    refreshContext()刷新上下文privatevoidrefreshContext(ConfigurableApplicationContextcontext){/***cintext=AnnotationConfigApplicationContext*/refresh(context);if(this.registerShutdownHook){ try{ context.registerShu......
  • invalidate the cache in Spark by running 'REFRESH TABLE tableName' command in SQ
    ...1moreCausedby:java.io.FileNotFoundException:Filedoesnotexist:hdfs://ns1/user/hive/warehouse/dw.db/dw_uniswapv3_position_detail/pk_day=1689552000000/part-00000-bbe52b3b-4963-4c76-9ba9-e315305baed7.c000Itispossibletheunderlyingfileshave......
  • 有关access_token与refresh_token 理解
    下面是对接各种平台api的流程一般操作流程是下面的1始通过用户授权获取code,2然后通过code获取到  access_token和 refresh_token   3访问api必须携带  access_token 举例access_token:aaaaexpires_in:10分钟refresh_token :  bbbrefresh_expires_......
  • P9431 [NAPC-#1] Stage3 - JRefreshers 题解
    传送门这个人赛时看错了几次题目导致样例调了1h。\(Sol1:n\leqslant10,T\leqslant10\)乱搞分。枚举跳跃的顺序,判断可不可行,最后取最大值,复杂度\(O((n-1)!)\)。\(Sol2:B\)感觉跟正解没什么关系,先说这个。特殊性质\(\mathbfB\):保证对于任意跳跃球\(u,v\),如......
  • 解决yum 不能更新问题 :yum 报错Loaded plugins: fastestmirror, refresh-packagekit,
    因为测试需要,安装了CentOS6.4,并需要安装kvm,虚拟Windows2008进行测试。实际操作中,因为CentOS6已经停止维护了,所以每一步操作基本都存在一些问题。Yum(全称为YellowdogUpdater,Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的......
  • 手动刷新refresh
    refresh1.es数据写入的流程对于任何数据库的写入来讲fsync刷盘虽然保证的数据的安全但是如果每次操作都必须fsync一次,那fsync操作将是一个巨大的操作代价,在衡量对数据安全与操作代价下,ES引入了一个较轻量的操作refresh操作来避免频繁的fsync操作。2.什么是refresh写入documen......
  • npm run refresh 命令报错 -4048
    Youcanrerunthecommandwith`--loglevel=verbose`toseethelogsinyour我的操作是把C:\Users\{账户}下的.npmrc文件,删除即可 参考文章:npm-install命令报错-4048_第三人格书的博客-CSDN博客......