Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Value is getting into table while debugging but not inserting

(0) ShareShare
ReportReport
Posted on by 170

Hi there,

select purchTable order by RecId desc
join PurchLine order by RecId desc
where PurchLine.PurchId == purchTable.PurchId
join Replacement order by RecId desc
where Replacement.ItemNumber == PurchLine.ItemId;
{
ttsbegin;
select forupdate Replacement
where Replacement.ItemNumber == PurchLine.ItemId;
Replacement.PONumber = purchTable.PurchId;
Replacement.APGSupplier = purchTable.PurchName;
Replacement.update();
ttscommit;
}

I have written this query to select latest record in purchtable form and to get it's item number, if that item number matches with item number in latest record of replacement form i need to insert that purchid and purchname in my replacement table record.

while debugging values are assigning but when i open my form those are not inserted even i checked in SQL in table also they are not inserting

i have written this in form datasource active() method.

please help me with this. 

  • Ganesh Potnuru Profile Picture
    170 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Gunjan Bhattachayya

    Great, it is working very fine. Thanks for your much needed help.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Ganesh,

    You could try this code and see if that works for you.

    select purchTable order by RecId desc
        join PurchLine order by RecId desc
            where PurchLine.PurchId == purchTable.PurchId
            join forUpdate Replacement order by RecId desc
                where Replacement.ItemNumber == PurchLine.ItemId;
    
    if (Replacement)
    {
        ttsbegin;
        
        Replacement.PONumber = purchTable.PurchId;
        Replacement.APGSupplier = purchTable.PurchName;
        Replacement.update();
        
        ttscommit;
    }

    Since these values in Replacement can change only when a purchase order line is inserted, I would suggest you place these changes in insert method of PurchLine table, rather than in your form. If you are on D365 F&O, you can create a CoC on PurchLine\insert method to get this working.

  • Ganesh Potnuru Profile Picture
    170 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Gunjan Bhattachayya 

    I'm finding latest purch table record if the item  matches with my latest record in replacement table item then I need to assign po number and supplier from purch table to replacement table and there is no  direct relation between purch table and replacement table so I used purch line table  which contains item id and my replacement table also have item id so I used this item id to find po number and supplier from purch table . The final need is if a new purchase order created my latest record in replacement has to check the item id is same or not as that latest our hase order if it same then I need to get that po number and supplier

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Ganesh,

    I still don't understand your requirement. You are finding the latest PurchLine record. Then you want to find the last record in Replacement table and check if the Item Id is the same as the Item Id from PurchLine record and insert a new record if they are the same. This way, if there are new purchase order lines are not created or if they are created with the same itemId, new records will keep on getting created in the Replacement table.

    Is this requirement correct?

  • Ganesh Potnuru Profile Picture
    170 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Gunjan Bhattachayya 

    yes, it is inserting in the first record it found in the table with the same item id but i want to insert in the latest record that is newly created record, could you please tell me how to achieve this.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Value is getting into table while debugging but not inserting

    Ganesh, You have called update() instead of insert(). Right now it will select the first record for Replacement table that has the same Item Id as the PurchLine ItemId and will update the values of PONumber and APGSupplier fields.

    In any case, active method is not the right place to write this logic. This could be a batch job that you could run at a user defined interval and should insert records into this table.

  • Ganesh Potnuru Profile Picture
    170 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Gunjan Bhattachayya

    I have written this on my custom "replacement form" active method and I just want to insert those values not update and i don't mean to use while select i removed "{" and update but still, it is not getting inserted while debugging values are getting assigned to replacement fields.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Value is getting into table while debugging but not inserting

    Hi Ganesh,

    In which form data source active method have you written this code and could you explain why you have done a table update on the active method?

    In the code above did you mean to use "while select" instead of select (since you have used "{")? Also, did you want to do an insert or an 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,272 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,931 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans