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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how to increment the field value from one table to another

(0) ShareShare
ReportReport
Posted on by 1,836
 I have a field in salesquotationtable ie quotationvalue  i have added same field in projtable, so the there can be multiple sales quotation of one projid,
so i want to increment the value of quotationvalue in projtable  every time  when a new quotation is created  and new value is added in quotation value of salesquotation table that value should get added in the quatationvalue field of projtable , can any on guide me how can i get this done and which method i need to use .
 
thanks ,
regards,
dinesh
I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at
    Hi Dinesh,
     
    I would suggest you to add your code in the insert method of the SalesQuotationTable. Inside that method you need to write update code based on ProjId on the ProjTable and update the Quotation value. You can use either COC for insert method or use OnInserted event handler.
     
    Thanks,
    Girish S.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi Girish thanks for reply 
     
    i got this method on salesquotation table ,can i use it in insert code of the table , it is find method but what if project id is blank how can i use this method .
     public static SalesQuotationTable findProjId(ProjId     _projId,
                                                  boolean   _forupdate = false)
        {
            SalesQuotationTable     salesQuotationTable;
    
            if (isConfigurationkeyEnabled(configurationKeyNum(Project)) && _projId)
            {
                salesQuotationTable.selectForUpdate(_forupdate);
    
                select firstonly salesQuotationTable
                    where salesQuotationTable.ProjIdRef == _projId;
            }
    
            return salesQuotationTable;
        }
     
  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at
    No, this method has nothing to do with your requirement. You want to change the number of in ProjTable when a record is inserted to or deleted from SalesQuotationTable. But this method isn't used in either case. It's used when some code what to find a record in SalesQuotationTable by ProjId.
     
    If you really must store the value in ProjTable (and you can't simply calculate it if needed), override insert() and delete() methods of SalesQuotationTable (or use corresponding events), find the related ProjTable (if any) and change the value there. And you'll likely need update() too, because ProjIdRef is editable (at least at table level).
  • GirishS Profile Picture
    27,827 Moderator on at
    This is a find method - Its used to find a record from the SalesQuotationTable.
    Just write COC or event handler for insert method.
     
    Thanks,
    Girish S.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi
    ,martin thanks for reply ,
     
    i had written the condition on insert method of the salesquotationtable  , will it work or i am missing something .
    [ExtensionOf(tableStr(SalesQuotationTable))]
    final class DT_SalesQuotationTable_Extension
    {
       public void Insert()
        {
            next Insert();
                
            SalesQuotationTable     salesQuotationTable;
            ProjTable               projTable;
          
            if(projTable.ProjId != "")
            {
                select sum(quotationValue) from salesQuotationTable
                     join projTable
                         where projTable.ProjId == this.ProjIdRef;
    
                projTable.quotationValue = salesQuotationTable.quotationValue;
                projTable.update();
            }
    
           
        }
    
    }
    thanks ,
    regards
    Dinesh
  • GirishS Profile Picture
    27,827 Moderator on at
    if(projTable.ProjId != "") - This line is wrong - Without adding the select statement, how will you get buffer for projTable?
    It should be if(this.ProjIdRef != ""). You need to check whether ProjidRef should be empty or not in SalesQuotationTable.
     
    Thanks,
    Girish S.
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at
    It's easy to find out - try your code and you'll see. You'll find that you'll never get into your "if" block, because you never put any value to your projTable variable. And there are other problems.
     
    I think you want something like this:
    public void insert()
    {
        ttsbegin;
    
        next insert();
            
        SalesQuotationTable::updateProjQuotationValue(this.ProjIdRef);
            
        ttscommit;
    }
    
    private static void updateProjQuotationValue(ProjId _projId)
    {
        if (!_projId)
        {
            return;
        }
        
        SalesQuotationTable quotation;
        
        select sum(QuotationValue) from quotation
            where quotation.ProjIdRef == _projId;
        
        ProjTable projTable = ProjTable::find(_projId, true);
        projTable.QuotationValue = quotation.QuotationValue;
        projTable.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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans