Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Fields are not being filled

(0) ShareShare
ReportReport
Posted on by 308
Hi,

I want to create project quotation by code. Below I've added the full code and it's working, however there are some issues.
 
1. SalesPrice is not being set, do i need to update salesQuotationLine.SalesPrice after i create the line? or is there a way to make it get reflected directly? Would this line of code be the issue?
salesQuotationLine.createLine(true, false, true, true, true, true);
 
2. In SalesQuotationLine: LinePropertyId and ProjectDescription  are not being auto populated


3. is there a better way to create it?



FullCode

    public ResContract createProjectQuotation(ReqContract _reqContract)
    {
        SalesQuotationTable             salesQuotationTable;
        SalesQuotationLine              salesQuotationLine;
        CustTable                             custTable;

        int                                        startLine = Global::infologLine();
        int                                        currentLine;
        str                                        errorMsg;
        System.Exception                ex;

        ResContract resContract;
        if(_reqContract)
        {
            try
            {
                changecompany(_reqContract.DataArea())
                {
                    ttsbegin;
                    select firstonly custTable where custTable.AccountNum == _reqContract.AccountNum();
                    if(!custTable)
                    {
                        throw Error(/Invalid customer account/);
                    }
                    else
                    {
                        salesQuotationTable.CustAccount = custTable.AccountNum;
                    }
                    salesQuotationTable.QuotationId  = NumberSeq::newGetNum(SalesParameters::numRefSalesQuotationId()).num();
                    salesQuotationTable.QuotationType           = QuotationType::Project;
                    salesQuotationTable.initValue();
                    salesQuotationTable.initFromCustTable();
                    if(_reqContract.Currency())
                    {
                        salesQuotationTable.CurrencyCode = _reqContract.Currency();
                    }
                    if(_reqContract.DeliveryName())
                    {
                        salesQuotationTable.DeliveryName = _reqContract.DeliveryName();
                    }
 
                    salesQuotationTable.CustomerRef = _reqContract.CustomerReference();
 
                    InventSite inventSite;
                    select firstonly inventSite where inventSite.SiteId == _reqContract.SiteId();
                    if(inventSite)
                    {
                        salesQuotationTable.InventSiteId = _reqContract.SiteId();
                        salesQuotationTable.modifiedInventSiteFromParent();
                    }
                    else
                    {
                        throw Error (strFmt(/SiteId :%1 is not found/, _reqContract.SiteId()));
                    }
                    salesQuotationTable.ReceiptDateRequested    = _reqContract.ReceiptDateRequested();
                    salesQuotationTable.QuotationName              = _reqContract.QuotationName();

                    QuotationType quotationType;
                    salesQuotationTable.QuotationType           = str2Enum(quotationType, _reqContract.QuotationType());
 
                    if(salesQuotationTable.validateWrite())
                    {
                        salesQuotationTable.insert();
                    }
                    else
                    {
                        throw error(/Insert failed/);
                    }
                    List projectQuotationLines =  new List(Types::Class);
                    projectQuotationLines = _reqContract.ProjectQuotationLines();
                    if(projectQuotationLines && projectQuotationLines.elements())
                    {
                        LineContract lineContract;
                        ListEnumerator linesEnum = projectQuotationLines.getEnumerator();
                        if(linesEnum)
                        {
                            while(linesEnum.moveNext())
                            {
                                lineContract = linesEnum.current();
                                if(lineContract)
                                {
                                    salesQuotationLine.clear();
                                    salesQuotationLine = this.createProjectQuoationLine(salesQuotationTable, lineContract, _reqContract);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw error(strFmt(/No project quoation lines found/));
                    }
                    resContract = new ResContract();
                    resContract.QuotationId(salesQuotationTable.QuotationId);
                    resContract.Success(true);
                    resContract.Message(/Success/);
                    ttscommit;
                }
            }
            catch(ex)
            {
               
                ResContract resContract = new ResContract();
                resContract.Success(NoYes::No);
                errorMsg = '';
                for(currentLine = startLine + 1; currentLine <= Global::infologLine(); currentLine++)
                {
                    errorMsg +=  infolog.text(currentLine) + '/';
                }
                startLine = currentLine - 1;
                resContract.Message(errorMsg);
            }

            }
        }
        else
        {
            //logic
        }
        return resContract;
    }
 

    public SalesQuotationLine createProjectQuoationLine(SalesQuotationTable _salesQuotationTable, LineContract _lineContract, ReqContract _reqContract)
    {
        SalesQuotationLine salesQuotationLine;
        salesQuotationLine.QuotationType           = QuotationType::Project;
        salesQuotationLine.initFromSalesQuotationTable(_salesQuotationTable);
        
        salesQuotationLine.initValue();
        salesQuotationLine.ProjTransType            = QuotationProjTransType::Item;
        salesQuotationLine.ItemId                    = _lineContract.ItemId();
        salesQuotationLine.SalesQty                 = _lineContract.SalesQty();
        salesQuotationLine.SalesPrice               = _lineContract.SalesPrice();
 
        salesQuotationLine.createLine(true, false, true, true, true, true);
 
        return salesQuotationLine;
    }
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,684 Super User 2024 Season 2 on at
    Fields are not being filled
    Hi Deldyn,
     
    Have you considered copying the method salesQuotationLine.createLine and change it to your own needs? Then you can prevent using an update after the insert. You can go for an update, but as mentioned, that might give update conflicts and has a small performance penalty. In case you would need to process 10000 records, a small performance penalty might become a headache. 
    On the other side, if you copy a method, it needs to be reviewed during updates if Microsoft made breaking changes.
  • DELDYN Profile Picture
    DELDYN 308 on at
    Fields are not being filled
    Hi Andre,

    I can call what is inside this method by calling this line of code:
    salesQuotationLine.mcrSalesQuotationLineOverride().PriceOverride = NoYes::No;


    ​​​​​​​ But what about LinePropertyId, as I mentioned LinePropertyId depends on ProjCategoryId, and ProjCategoryId gets defined in the createLine method. So i need to update after the insert anyway, so i can update salesPrice with it as well.
    Unless you want me to define projCategoryId when creating the line, but this will cause the code to be repeated again when the createLine gets called.

    So what is better now to update both values (SalesPrice and LinePropertId) after the insert, OR to do this while creating salesQuotaitonLine?

    salesQuotationLine.mcrSalesQuotationLineOverride().PriceOverride = NoYes::No;
    salesQuotationLine.SalesPrice = _lineContract.SalesPirce();
    salesQuotationLine.ProjCategoryId = inventTable.ProjCategoryId ? inventTable.ProjCategoryId : salesQuotationLine.ProjCategoryId; // this line of code will get called again with createLine method
    salesQuotationLine.LinePropertyId = ProjLinePropertySetup::findLinePropertyId(salesQuotationLine.salesQuotationTable().ProjIdRef, salesQuotationLineLocal.ProjCategoryId);​​​​​​​

    salesQuotationLine.createLine(true, false, true, true, true, true);

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,684 Super User 2024 Season 2 on at
    Fields are not being filled
    Hi Deldyn,
     
    Initially, I would try to ensure that the method SalesQuotationLineType.mustOverrideQuotationLinePrice() will return false. Not sure how easy that will be with setting a variable or a code extension. Updating afterwards can cause update conflicts and has an additional performance penalty.
     
     
     
     
  • DELDYN Profile Picture
    DELDYN 308 on at
    Fields are not being filled
    Hi Andre,

    For the salesPrice, I already debugged and yes the reqContract contains the correct value for price, but it gets deleted inside createLine. If you want the exact method that causes this, then it's this one:
    SalesQuotationLineType.mustOverrideQuotationLinePrice() -- So my question is, what is better, to create a new method to update salesPrice after the insert finishes or let the method retrun false?

    For the LinePropertyId, i saw a place where it get defined by this and it worked
     salesQuotationLine.LinePropertyId = ProjLinePropertySetup::findLinePropertyId(salesQuotationLine.salesQuotationTable().ProjIdRef, salesQuotationLine.ProjCategoryId);
    However, ProjCategoryId gets defined inside the createLine method, so i will need to also update LineProperyId after the insert finished
     
        public void updateProjectQuoationLine(SalesQuotationLine _salesQuotationLine, LineContract _lineContract)
        {
            SalesQuotationLine salesQuotationLineLocal;
            select firstonly forupdate salesQuotationLineLocal where salesQuotationLineLocal.QuotationId == _salesQuotationLine.QuotationId
                                    && salesQuotationLineLocal.LineNum == _salesQuotationLine.LineNum;
     
            salesQuotationLineLocal.SalesPrice  = _projectQuotationLineContract.SalesPrice();
            salesQuotationLineLocal.setLineAmount();
            salesQuotationLineLocal.LinePropertyId = ProjLinePropertySetup::findLinePropertyId(salesQuotationLineLocal.salesQuotationTable().ProjIdRef, salesQuotationLineLocal.ProjCategoryId);
            salesQuotationLineLocal.update();
        }

    For the ProjDescription, I added this line when creating the line and it worked
    salesQuotationLine.ProjDescription = InventTable::find(salesQuotationLine.ItemId).productName(salesQuotationTable.LanguageId, salesQuotationLine.InventDimId);
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,684 Super User 2024 Season 2 on at
    Fields are not being filled
    Hi Deldyn,
     
    For the sales price, I would suggest using the debugger to find out if the lineContract.SalesPrice() is returning a value or if it gets lost in the salesQuotationLine.createLine() method.
     
    For the auto-creation of some other field values, I don't see any coding. You can check if there are methods that you can call to have these fields filled. Maybe there is some logic on modifiedField or on another initFrom.... method.
  • DELDYN Profile Picture
    DELDYN 308 on at
    Fields are not being filled
    Any idea?

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,684 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,414 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans