Skip to main content

Notifications

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,479
 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
  • Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    how to increment the field value from one table to another
    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();
    }
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    how to increment the field value from one table to another
    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.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    how to increment the field value from one table to another
    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
    GirishS 27,821 Super User 2024 Season 1 on at
    how to increment the field value from one table to another
    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.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    how to increment the field value from one table to another
    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).
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    how to increment the field value from one table to another
    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;
        }
     
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    how to increment the field value from one table to another
    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.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans