When users are adding Quote Products to a Quote through the Products/Add Products section, often they find that when they return to the quote, the order that they selected the products has not been retained.

There is a LineItemNumber field in the QuoteProducts that could be used, however this would require manual entry which does not seem feasible, my thoughts are that a counting sequence for each quote could be used and the InLine view could be sorted based on this counting number.

I could add a auto-sequencing field to Quote Products but this wouldn't relate to the specific quote and would count without reference, this would work in theory in terms of sorting the quote, but I don't feel it is a rounded solution.

Viewing older posts I found the following discussion:

 Line Item Number in Quote Product 

It details using JS and an OnTrigger event to automatically count in sequence depending on if it finds a match for the Quote GUID, I've adapted the following code and have it working in Sandbox, but it only works when actually going into the Quote Products form, and not using the 'Add Products' feature:

function Line_OnSave()
    if (Xrm.Page.getAttribute("lineitemnumber").getValue() == null) {
        var serverUrl = Xrm.Page.context.getClientUrl();
        var QuoteGuid = Xrm.Page.getAttribute("quoteid").getValue()[0].id;
        var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/QuoteDetailSet?$select=LineItemNumber&$orderby=LineItemNumber desc&$filter=QuoteId/Id eq guid'" + QuoteGuid + "'&$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) + 1000);
                    else {
Is there a way this could be adapted to trigger when the Add Products event occurs, or is there potentially a different way that I could achieve auto sequencing for Quote Products within a Quote?