Friday, November 22, 2013

AX2012:Restore or (Ctrl + F5) command on forms using X++ code

Hi Friends,
This is a simple tip but good to keep the information handy.
When the records displayed on the form are updated by some other process we get an error "The values displayed in the form are not current, so an update or deletion cannot be made. To view the current values, on the Command menu, click Restore or press CTRL+F5".

In one of my recent projects, there was a situation when I wanted execute ctrl+ F5 command from code. I looked into the task macro but this command was not defined there so the challenge was to find the task id for this command so that I can pass it in element.task() method.

In order to get this task ID, I override the task method on the form and enabled debugger, opened the form and pressed ctrl + F5. The method was called and I got the task ID as 2839.

So in order to execute ctrl+F5 just call element.task(2839) and the record values will be restored.

You can also find task ID of other commands using this approach.

Thanks for reading the blog.
Keep sharing.

3 comments:

  1. This is not the right approach. The reason for the “values displayed in the form are not current..” error is because of fields that are updated in the datasource’s active() method.
    If you force an element refresh, the data is read from the table again and any changes made by the user is lost.
    The best way to fix this is to remove the code that update the field values in the active method of the datasource.

    ReplyDelete
    Replies
    1. Thanks Celeste. Appreciate your feedback. My main intention is to show how we can track the task ID of any specific event. I agree we should not ignore of try to supress this message.

      Regards,
      Rachit Garg

      Delete