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)

init() code on Sales order tied to return order

(0) ShareShare
ReportReport
Posted on by 282

Hi all

Running AX 2012 R3 CU9.

I'm running into a small dilemma. I have code which runs on the SalesTable file, when a sales order is created. Normally, I would put this in init() or modifiedField(), but for some reason, the code won't run when the sales order is created off the back of a new returns order.

I've tried putting it in modifiedField() where _fieldId is the SalesType, and it was already in init() - I don't see a specific init() for returns orders. At a loss as to where to put this code to force it to run.

Some additional detail as to the purpose of the code: takes a value from the customer at time of creation, and uses it to populate a flag which we use for reporting purposes.

If you could offer any help this would be much appreciated

Thanks very much

Luke

*This post is locked for comments

I have the same question (0)
  • lukbel Profile Picture
    282 on at

    Hi, bumping this thread as it has not received any response?

    Any help would be appreciated

    Thanks very much

    Luke

  • Community Member Profile Picture
    on at

    Lukbel,

    I couldn't understand your statement well.

    You wrote a code in init and its not working at init but working in ModifiedField? This is what you are saying? or what?

  • lukbel Profile Picture
    282 on at

    Hi Hafiz

    No, my apologies - should've been more clear.

    In order to make this code calculate on the SO being created but make sure after customer account is set, I put it in modifiedField(), where _fieldId == CustAccount.

    This works for all new Sales orders except these return order SOs. The value will not change after being set, so it's just a case of setting the value when it's created (however, I know already that init() does not work in this case).

    Do you know where I could set the value for these return order SOs?

    Thanks

    Luke

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    modifiedField is not invoked unless human interaction is involved (typically and normally). If you want something to happen on creation of record insert() method is usually the place. For case for sales order and purchase order (kind of trading docs) insert is overtaken by associated classes such as SalesTableType and PurchTableType.

    For your specific case, as return order can be created using an existing SO, this means your user is not really selecting a customer at time of creating a return order from existing SO. This can be otherwise only, if user hits New Order and select order type as Return Order.

    Long story short, you should see, how your return order is created, if this is by selecting an existing SO, and hitting credit Note, please don’t expect the init method or modifiedField() to be invoked.

  • lukbel Profile Picture
    282 on at

    Hi Sohaib,

    Thanks for explanation - that makes a lot of sense, I understand now.

    They are creating the record through form All returns orders > New returns order. As far as I know that is the only method of creation. I am struggling to see what method this calls. Could you illuminate this?

    However, for sake of peace of mind, if they create from new order and selects order type Return order, knowing this would also be helpful.

    Thanks very much for your help so far

    Luke

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Hi Lukbel,

    I would like if you may add your business requirement details. Please forget about code for a moment and tell us what you want to get, by imagining I don’t know coding.

  • lukbel Profile Picture
    282 on at

    Hi Sohaib

    Basically, we have a flag field which we pass from the Sales order to our paperwork. The user can change this, and it will change the format of, for example, the invoice (summarising field breakdowns etc).

    The initial value of this field is inherited from a similar field in the customer table, which acts as a default. So, when the user creates a sales order or quotation, the value against the customer is set as the value for that sales order, and can then be changed if necessary.

    My problem is that this last piece of functionality (inheriting from customer) does not work against the sales order when the sales order is a returns order.

    My apologies, I should've explained in that amount of detail in my opening post

    As before, any help you can offer would be much appreciated :)

    Thanks

    Luke

  • Verified answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Hi Lukbel,

    Thank you for your explanation. It sounds good now.

    When we are talking about utilizing field from Customer master that means utilization of following method on SalesTable.

    AOT\Data Dictionary\Tables\SalesTable\Methods\initFromCustTable

    As return order can be created from sales order itself as well, by hitting the Credit Note button, so there can be situation when initFromCustTable may not be invoked.

     

    A safe point can be adding your code at following location before keyword salesTable.doInsert();

    AOT\Classes\SalesTableType\insert

     

    By putting your code in insert() method of SalesTableType, we can make sure that code will be executed every time when a new record will be created in sales order table.

     

    Give it a try and let us know how it goes.

  • lukbel Profile Picture
    282 on at

    Brilliant, exactly where I needed it :)

    I will need to test this with code I already have in initfromSalesQuotationTable(), CustTable() etc. But I didn't know this class existed, so I think this will also be able to make my current setup much neater!

    Thanks very much for all your help

    Cheers

    Luke

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