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

Announcements

No record found.

News and Announcements icon
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)
  • Suggested answer
    jlattimer Profile Picture
    24,564 on at

    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();
        }
    }
    
  • Thadd.Bo Profile Picture
    760 on at

    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.

  • jlattimer Profile Picture
    24,564 on at

    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

    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?

  • jregan Profile Picture
    674 on at

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

  • Verified answer
    jlattimer Profile Picture
    24,564 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans