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)

How to extend form data source initValue method

(0) ShareShare
ReportReport
Posted on by 1,650

Hello,

I would like to change the value of the field "AttributeModifier" in the initValue() method of a datasource (EcoResAttribute). The method on the form is implemented in the following way:

public void initValue()

{

super();

//the purpose of the below default assignment is to restrict the users to create attributes of type Catalog

// and later can be consumed by Categories and Products.

ecoResAttribute.AttributeModifier = EcoResAttributeModifier::Catalog;

}

I tried to handle my requirement with the "event handler" method in order not to overlayer the form. I chose the event "OnInitValue".

Unfortunatly is the code in the event handler executed during the "super()" context of the form method. Therefore the line "ecoResAttribute.AttributeModifier = EcoResAttributeModifier::Catalog;" afterwards orverrides my value.

29_2D00_08_2D005F00_2017_5F00_14_2D00_31_2D00_01.jpg

How can I change the value in the field "EcoResAttribute.AttributeModifer" in the initValue() without overlayering the form?

Thanks in advance

Sebastian

*This post is locked for comments

I have the same question (0)
  • Sebastian Aurand Profile Picture
    1,650 on at

    Thanks for the response. The "onInitialized" event you mentioned is connected to the "form data source init method", which will NOT initialize the values on a new record. Please refere to this list:

    docs.microsoft.com/.../customization-overlayering-extensions

  • Temur Mukbaniani Profile Picture
    260 on at

    You can also try to create extension class for EcoResAttribute table and copy corresponding table events which match your requirement.

    docs.microsoft.com/.../add-method-table

  • Sebastian Aurand Profile Picture
    1,650 on at

    Unfortunatly I need the form context (args = set on the calling menu item) to decide which value needs to be initialized. This context is not available at the table level.

    Furthermore I guess that the "initValue" method of the table will also be executed in the "super()" context of the form data source initvalue method and therefore the line after the super() call mentioned in the original post will override the value.

  • Sebastian Aurand Profile Picture
    1,650 on at

    As mentioned above I need the form context to decide which value should be written to the field.

    A possibility is to set the value in the "OnWriting" event of the datasource. But the value is also shown in the form and in the initialize status (Button "New" is selected) of the record it will show the original "wrong" value, which will change in the insert / write phase of the record.

    This might confuse the user but will keep the data consistent. I guess I will stick with this solution until (hopefully) the event "onInitializedValue" (executed after the standard initValue of the form datasource) will be provided.

    Thanks for all reponses.

  • Verified answer
    Sebastian Aurand Profile Picture
    1,650 on at

    Just to finish this question. I handled the value in the "onCreated" event in the formdatasource. The user experience is fine.

  • TestBot Profile Picture
    950 on at

    Hi,

    Sebastian Aurand

    Can u send the sample code for the eventhandler you used to solve the issue.

    my requirement is similar to your requirement, my value is coming from formdatasource initvalue method , using this value ,i have to convert and put inanother field without overlayering. please suggest me where to write(table/fds) exact code to get done. 

  • Sebastian Aurand Profile Picture
    1,650 on at

    Hi,

    this is my event handler:

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [FormDataSourceEventHandler(formDataSourceStr(EcoResAttribute, EcoResAttribute), FormDataSourceEventType::Created)]

    public static void EcoResAttribute_OnCreated(FormDataSource sender, FormDataSourceEventArgs e)

    {

    FormRun formRun = sender.formRun();

    EcoResAttribute ecoResAttribute = sender.cursor();

    ;

    if (formRun.args().parmEnumType()

    && formRun.args().parmEnumType() == enumNum(EcoResAttributeModifier)

    && formRun.args().parmEnum() == EcoResAttributeModifier::MyDirParty)

    {

    ecoResAttribute.AttributeModifier = EcoResAttributeModifier::MyDirParty;

    }

    }

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans