web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

update record in formdatasource extension

(0) ShareShare
ReportReport
Posted on by 1,271

Hello,

I'm trying to update the record in write() method of the standard formdatasource extension. t

[ExtensionOf(FormDataSourceStr(PurchCreateOrder, PurchTable))]
internal final class PurchCreateOrder_Form_PurchTableDS_Extension
{
    void write()
    {
        next write();

        FormDataSource purchTableDS = this;
        Purchtable purchTableCursor = purchTableDS.cursor() as PurchTable;
        PurchTable purchTable = Purchtable::find(purchTableCursor.PurchId,true);

        ttsbegin;

        purchTable.TaxGroup = sometable::find(purchtable.InventSiteId,purchtable.InventLocationId).TaxGroup;
        purchTable.DefaultDimension = changeFinancialDimensionValue(purchTable.DefaultDimension,
                                                                    'Location',
                                                                    sometable::find(purchTable.InventSiteId,purchTable.InventLocationId).LocationFinDim
                                                                    );
        purchTable.update();


        ttscommit;
    }

}

the record is already inserted in standard write() method. then I get the cursor and it contains purchid value but then the system doesn't find purchtable. it's always null value. what am I doing wrong? I tried simply use purchTable without finding cursor. It's also doesn't work. FO doesn't see it in the code below saying that purchTable isn't reachable:

[ExtensionOf(FormDataSourceStr(PurchCreateOrder, PurchTable))]
internal final class PurchCreateOrder_Form_PurchTableDS_Extension
{
    void write()
    {
        next write();


        ttsbegin;
        
        
        purchTable.selectforupdate();
        purchTable.TaxGroup = sometable::find(purchtable.InventSiteId,purchtable.InventLocationId).TaxGroup;
        purchTable.DefaultDimension = changeFinancialDimensionValue(purchTable.DefaultDimension,
                                                                    'Location',
                                                                    sometable::find(purchTable.InventSiteId,purchTable.InventLocationId).LocationFinDim
                                                                    );
        purchTable.update();


        ttscommit;
    }

}

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,218 Most Valuable Professional on at

    Hi, could you tell us what is to trigger the system to update the record ?

    At what point do you want to update this record?

  • dark_knight Profile Picture
    1,271 on at

    It's standard PurchCreateOrder form (called when you create new PurchOrder in user interface) and purchtable is inserted in PurchTableDS write() method.

  • Komi Siabi Profile Picture
    13,218 Most Valuable Professional on at

    What is the business scenario ?

  • GirishS Profile Picture
    27,843 Moderator on at

    Hi Azat,

    You need to create new buffer for PurchTable and get the current cursor like below.

    PurchTable purchTableBuffer;

    purchTableBuffer = this.cursor();

    Now you can get the value in the purchTableBuffer.

    Thanks,

    Girish S.

  • Mariano Gracia Profile Picture
    on at

    The purchcreateorder form is a bit special, I suggest you to use the public variable purchTableForm in the write method extension, and then call the method purchTableForm.purchTable(), it will give you the purchtable record created by the form.

  • dark_knight Profile Picture
    1,271 on at

    The purchcreateorder form is a bit special, I suggest you to use the public variable purchTableForm in the write method extension, and then call the method purchTableForm.purchTable(), it will give you the purchtable record created by the form.

    Like0 Likes

    Moderate

    thanks. interesting.

    do you have an example?

  • Verified answer
    Mariano Gracia Profile Picture
    on at

    You'll need two extensions, the first one to make the PurchTableForm variable accessible:

    [ExtensionOf(formStr(PurchCreateOrder))]
    public final class PurchCreateOrderGVC_Extension
    {
        //We need to access the purchTableForm variable, so we make a new method to return it
        public PurchTableForm purchTableForm()
        {
            return purchTableForm;
        }
    
    }

    and the second one an extension of the PurchTableCreateOrder's PurchTable datasource in wich you'll update the record in the write event, now I only show an info so you can verify you get the record you want to modify:

    [ExtensionOf(formDataSourceStr(PurchCreateOrder, PurchTable))]
    public final class PurchCreateOrder_PurchTableGVC_Extension
    {
        //write extension on the datasource to access the created PurchTable record
        void write()
        {
            next write();
    
            if (element.closedOk())
            {
                FormRun     formRun = this.formRun();
    
                if (formHasMethod(formRun, identifierStr(purchTableForm)))
                {
                    PurchTableForm  purchTableFormLocal = formRun.purchTableForm();
                    PurchTable      purchTableToUpdate = purchTableFormLocal.purchTable();
    
                    info(purchTableToUpdate.PurchId);
                }
            }
        }
    
    }

  • dark_knight Profile Picture
    1,271 on at

    thank you. will do

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 591

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 550 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 543 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans