Quick Tip: Creating Dexterity System Variables

David Meego - Click for blog homepageThis is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.

Hi everyone.

This is another Quick Tip post for Dexterity developers. Vaidy’s recent post: “Illegal Address Field” Error while accessing a Global, raised the issue and so I thought I would respond with an explanation.

The issue is when you create a System Variable (global variable) from an existing Dynamics Global Field.  While you are in test mode, the code will work fine, but once a chunk is created you will get the following error:

Unhandled script exception: Illegal address for field ‘<Field Name>’ in script <Script Name>. Script terminated.

The reason for this is easy to explain, once you understand how Dexterity handles the System Variable resources. System Variables are stored in application memory and can be referred with the “of globals” qualification.

System Variables are not actually stored as separate resources in the Dexterity dictionary. They are a subset of the Global Field resources, with a flag to mark them as System Variables. So the act of adding a System Variable does not create a new resource, but just edits the existing resource.

The scripts that use this newly added System Variable will compile and work fine when running in Dexterity Test Mode. However, once a chunk of the code has been created and installed into Runtime mode, you will get errors whenever the System Variable is referenced because it does not exist in the runtime environment.

Because we updated an existing variable with a Resource ID less than 22,000, it is not transferred into our addon dictionary during the extract stage of the chunking process. So in Runtime mode, the original field in the DYNAMICS.DIC is being used and this field is not marked as a System Variable.

The solution is to always create your own Global Field resource and then add it as a System Variable when you need a global variable. I always prefix its name with my company identifier (“MBS”) and include a description of the field’s purpose in the name. Now the will be a new resource with an ID greater than 22,000 which will be extracted when my chunk is created.

Note: Other common reason for the above error message are discussed in the following posts: Dex – Illegal address for field ‘PowerUser’ exception and Quick Tip: Solving Illegal Address Errors on Alternate Windows after installing a Service Pack.

Hope this explains what happened.

David

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

4 thoughts on “Quick Tip: Creating Dexterity System Variables

  1. Thank you very much, David. I was sure I must create my own field and add it to globals, but I never knew till now about how globals work in Dex. Now I know the background. Thanks again.

    Like

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.