Skip to main content

Notifications

Announcements

No record found.

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

Value is getting into table while debugging but not inserting

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
    Ganesh Potnuru 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
    Gunjan Bhattachayya 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
    Ganesh Potnuru 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
    Gunjan Bhattachayya 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
    Ganesh Potnuru 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
    Gunjan Bhattachayya 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
    Ganesh Potnuru 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
    Gunjan Bhattachayya 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

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans