Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

Posted on by 529

Hello,

I have attached a new button in the ProdTableListPage's action Pane. I need to write a clicked method to stop any active jobs on the selected production record.

I only find a Command property for that button but I dont know where exacly is that method supposed to be modified/coded?

pastedimage1587389543884v1.png

Thanks a lot before hand for your kind help

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    RecVersion is always changed when you update a record. It does not matter which field(s) in the record were changed.

    If you don't get such error, it only means that your process is not trying to update a record using an outdated RecVersion.

  • CBNestor Profile Picture
    CBNestor 529 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    Perfect explanation Nikolaos,

    In the case of updating the record but at a new custom field, this RecVersion is not changed?. is that correct?.

    because at first time just by updating my custom NoYes field in the production table did not received any error of "The values displayed in the form are not current"

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    It's needed so that the form will get an up-to-date record (that your code manipulated).

    If the record is not up to date, you will get an error if you try to update something on the form (like you noticed).

    This mechanism exists to prevent users and processes from accidentally overwriting each other's changes in the records.

    Here's how it works:

    1) When open the form, records are loaded from the database and stored in the client. Each record contains RecVersion field.

    2) While the form is open, your button changes a record. This update changes RecVersion of the record in the database

    3) Now if you try to change the same record on the form, the client notices that RecVersion of the record that is being saved, and RecVersion in the database are not the same. This means that someone else changed the record, and if your save would be succesful it would overwrite those changes. Even if you change only field A, actually the whole record with all field values is always saved, so if any other field was changed by that other process, those changes would disappear when you save your (outdated) record.

    4) With refresh/research, latest version is fetched from the database, and you are now working with the latest version

  • Suggested answer
    CBNestor Profile Picture
    CBNestor 529 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    tried with :

       FormControl _fc;

       _fc = _args.callerFormControl();

       _fc.dataSourceObject().refresh();

       _fc.dataSourceObject().research(true);

    unthough I don't know excalcly why is must to do that is working perfect :)

    Thanks a lot Nikolaos thanks a lot for your help!

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    Try _args.record().dataSource().

  • CBNestor Profile Picture
    CBNestor 529 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    My code is on the class called by the MenuItem as you said I have access only to Main (Args _args)

    how do i get to  the formDataSource?

    I know I ask to much but I am very close to finish . appreciated with your help

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    After running your logic, you should refresh the form data source by calling [formDataSource].refresh() followed by [formDataSource].research(true).

  • CBNestor Profile Picture
    CBNestor 529 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    Hi Nikolaos,

    1) I managed to follow your suggestions. At first time when clicking the button it updates the custom field and also in the list page automatically. this part is ok so far.

    2) Now I have used the JmgJobBundle class to stop any active jobs from the production selected when button is clicked. This is also doing ok. but when I try updating the field again in 1)

    throws an error that says: Cannot edit a record in Production orders (ProdTable).
    The values displayed in the form are not current, so an update or deletion cannot be made. To view the current values, on the Command menu, click Restore or press CTRL+F5.

    part of the code inspired by \Clases\JmgTermCloseOpenregTrans . createStopRegisterationJob()

    pastedimage1587566314316v1.pngpastedimage1587566634363v2.png

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    1) Update_recordset is not making much sense since you update only one record (since RecId is unique in each table).

    You will always need a transaction (ttsbegin/ttscommit) if you update data. No matter if you use update_recordset or not.

    2) Check ProdTableListPageInteraction\setButtonAccess

  • CBNestor Profile Picture
    CBNestor 529 on at
    RE: Howto code ComandButton clicked Method in List page's action pane (to stop production jobs registration)

    Hi Nikolaos,

    I have followed your recomendation. I added the a menuItemButton and managed to code the basis of what I need ( update the custom NoYes record after button clicked)

    1) I wonder if this code is according to the best practices or I need to improve a little bit ( used the Update_recorset instead of ttsbegin/ttscommit)

    pastedimage1587455821245v1.png

    2) How do I call the Button control, so I can disable the button after update?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans