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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Validate a field while modifying another

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I have a forum with two text fields, field A of size 1000 chars and field B of size 255 chars.

I am duplicating/mirroring content of field A to field B while field A is being modified.

I want to show an error message and mark field B in red when it exceeds 255 chars while field A is being modified.

How do I go about that?

I have tried validateWrite(), and tried to call validateField() method while field A is being modified, it kind of works, I get the correct error message, however the wrong field is marked in red (field A is marked in read instead of field B)

My code (it works, only the wrong field is marked in red):

0755.img-1.PNG

3301.img-2.PNG

0564.img-3.PNG

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi Sar Sa,

    You can make use of the Datasource field level modified method to assign values from field A to field B and also update the field b color.

    To throw validation you can make use of table level "validateField" method.

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    First of all, why do you want to store the same information twice? You should have a good reason for this violation of DB design rules? Also, what's the point of having 1000 characters for field A if it's not allowed to have more than 255?

    Second, you said that "the wrong field is marked in red (field A is marked in read instead of field B)", but field A sounds like the right field to me. The problem is in field A. You're checking whether field A doesn't contain more than 255 characters. You aren't validating field B (which is guaranteed not to have more than 255 characters anyway).

    By the way, which version of AX is it about?

  • Sar Sa Profile Picture
    5 on at

    Field A will contain a large description of a product, while field B will store a shorter version of that description to be printed on a PDF document. The idea is to copy over content of field A to field B automatically, then adjust field B a little (shorten it if longer than 255 it and modify it somewhat). The customer does not want to have to manually copy content of field A to field B, they want it to happen automatically to save time.

    Both fields allow the user to enter 1000 chars (user is not prevented from entering more than 255 chars in field B), but I am validating field B in the code. we don't want to restrict field B to 255, to allow the duplication to happen. Using the latest version I think.

  • Sar Sa Profile Picture
    5 on at

    How do I update field color?

  • GirishS Profile Picture
    27,827 Moderator on at

    Please go through the below url for change grid cell color.

    https://dhruvrthakar.blogspot.com/2017/10/change-color-of-row-column-or-specific.html

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Please stay on topic. Changing a color isn't a solution for the question about the validation.

    If your intention was starting a discussion about a new topic, please create a new thread for it. Choose an apprpriate title, select the version of AX and explain your problem in detail there.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Sar Sa, can you show us your code, please? It's not clear to me what exactly you did in validateWrite() and validateField().

    Also, you still didn't tell us which version of AX is it about (and you created the thread with "Don't know" as the version). Please give us the answer.

  • Sar Sa Profile Picture
    5 on at

    Updated my post with the code

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    It's a pity that you again failed to tell us anything about the version, but your screenshots show that it's not about Dynamics AX at all. You're using D365FO. I'm going to move this thread to the right forum.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Regarding your code... You seem to want to run your logic when modifying the field, not when saving the record, right?

    Your call of validateWrite() in modifiedField() looks weird to me. You also ingore the return value, so does nothing exept of adding one more infolog message. I guess we can ignore this call, can't we?

    Also, did you consider doing the validation just on record saving? Would it be a problem?

    By the way, the following piece of code is over-complicated and it contains a field name hard-coded at text. That's wrong, because such texts aren't validate by compiler and the usage of the field wouldn't appear in References.

    DictTable dt;
    fieldId fId;
    dt = new DictTable(tableNum(TableX));
    if (dt)
    {
        fId c= dt.fieldName2Id("Field_B");
    	this.validateField(fId);
    }

    It can be replaced with something much simpler, and safer:

    this.validateField(fieldNum(TableX, Field_B));

    By the way, working with your code would be much easier if you provided it as text and not as pictures. Next time, please copy your code and paste it with Insert > Code (in the rich formatting view). That's what I did.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans