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 :
Microsoft Dynamics AX (Archived)

Getting data from a field that might not exist

(0) ShareShare
ReportReport
Posted on by

Hi

I have created a method that reads data from a table.

However, all of our customers might not have one of the fields that are read in this method. Nevermind why :-)

So I want to make sure that this method will still compile and run in all systems.

So...how can I check if the field exists in the table and how can I read the data from the field if it exists?

Thanks!

/Jonas

 

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I recommend to adjust an application architecture (layers, configuration keys or so), because that it a real source of problems.

    Anyway, the easiest code-based solution is probably this one:

    fieldId = fieldName2Id(buffer.TableId, 'FieldName');
    if (fieldId) { value = buffer.(fieldId); }

    You lose, of course, all compilation-time checks, cross references etc.

    Another solution would be to use preprocessor macros to achieve a conditional compilation, but I strongly recommend to avoid it.


  • Community Member Profile Picture
    on at

    Thanks Martin.

    Just as a quick response, the reason I need this is that the new field is part of a large update that cannot be performed right now, but this new method needs to be deployed immediately and I did not want to comment out a certain line for just one customer, since that would probably cause even more trouble if I forget to add it again :-)

  • Denis Patrakov Profile Picture
    on at

    You can deploy this new method with the new field to all your customers right now - just set the field's SaveContents property to No (and maybe Visible to No, too) so that it doesn't appear in the database after synchronization - if this is what you are concerned about. Your large update then would change SaveContents to Yes for this field. Although a new configuration key would be a better solution.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans