web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Line Item Number in Quote Product

(0) ShareShare
ReportReport
Posted on by 760

Hello,

The quote products are sorted by product name but there is also a field called lineitemnumber, which seems to to be utilized. I would like to use it and order the products by this number.

Is there a little script that increased the lineitemnumber automatically if user add a new product?

Thank you for your help.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    jlattimer Profile Picture
    24,562 on at
    RE: Line Item Number in Quote Product

    A couple links that might help:

    Creating A JavaScript Web Resource

    Use A JavaScript Web Resource In Your Form

    It would attach to the form's OnSave event

  • jregan Profile Picture
    674 on at
    RE: Line Item Number in Quote Product

    Where would I add this script to create the line number?

  • Thadd.Bo Profile Picture
    760 on at
    RE: Line Item Number in Quote Product

    Thank you, I will try this.

    Regarding the offline function is the query to get the latest line number not been made to the local database? So then there would be no problem?

  • jlattimer Profile Picture
    24,562 on at
    RE: Line Item Number in Quote Product

    Essentially you can change out 'Opportunity' with 'Quote' and it would work.

    This would not work offline as when the line item is saved a query is being made to the system to get the last  line number used. Being that this is done in real-time there is't any capacity to handle this a user comes back online.

  • Thadd.Bo Profile Picture
    760 on at
    RE: Line Item Number in Quote Product

    Hi Jason,

    this is great and the solution would with scripting would be ok but we do not use opportunitites we just right with the quote so does this code works also for quote or the quote producuts?

    Does this also work in Outlook with offline mode?

    Thank you already for your help.

  • Suggested answer
    jlattimer Profile Picture
    24,562 on at
    RE: Line Item Number in Quote Product

    The best way would really be to use plugins but this code will increment line numbers. Basically it retrieves the last line item from the parent (in the case Opportunity) and adds 1. It doesn't do anything as far as re-ordering items is one of deleted of anything fancy - just the basic increment.

    Make sure you have the LineItemNumber field on the form and add this code the the line item form's OnSave event.

    function Line_OnSave() {
        if (Xrm.Page.getAttribute("lineitemnumber").getValue() == null) {
            var serverUrl = Xrm.Page.context.getClientUrl();
            var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/OpportunityProductSet?$select=LineItemNumber&$orderby=LineItemNumber desc&$filter=OpportunityId/Id eq guid'" + Xrm.Page.context.getQueryStringParameters()._CreateFromId + "'&$top=1";
            var req = new XMLHttpRequest();
            req.open("GET", oDataSelect, false);
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
            req.onreadystatechange = function () {
                if (req.readyState === 4) {
                    if (req.status === 200) {
                        var retrieved = JSON.parse(req.responseText).d;
                        if (retrieved.results.length > 0) {
                            Xrm.Page.getAttribute("lineitemnumber").setValue(parseInt(retrieved.results[0].LineItemNumber) + 1);
                        }
                        else {
                            Xrm.Page.getAttribute("lineitemnumber").setValue(1);
                        }
                    }
                }
            };
            req.send();
        }
    }
    

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans