You need to sign in to do that
Don't have an account?

How to change Quote Line Item sort order
I am trying to write a trigger to chang the quotelineitem's sort order by copying the item number, which is a custom field. I am recieving the following error:
Compile Error: Field is not writeable: QuoteLineItem.SortOrder
Here is my code:
trigger LineItemSortOrder on QuoteLineItem (Before Insert, Before Update) { QuoteLineItem[] q = trigger.new; for (integer i = 0; i < q.size(); i++) { QuoteLineItem nquote = q[i]; nquote.sortorder = integer.valueof(nquote.Item__c); } }
Is there any way around this error?
Thank you,
ckellie
Thank you for the link.
I have customized the script as needed and habe adeded the script to the page layou via apex button. I have customized the button to order the Quote Item number, Unfortunately the button is not doing anything. What am I doing wrong and what do I need to change?
Javascript button:
Aperx Class:
What am I dong wrong and how do I fix it?
regards,
ckellie
All Answers
See http://boards.developerforce.com/t5/Visualforce-Development/Re-opening-the-disscussion-of-SortOrder-on-OpportunityLineItem/m-p/260295#M33758 for the unfortunately complicated workaround I came up with. It is for OpportunityLineItem but works the same for QuoteLineItem.
Thank you for the link.
I have customized the script as needed and habe adeded the script to the page layou via apex button. I have customized the button to order the Quote Item number, Unfortunately the button is not doing anything. What am I doing wrong and what do I need to change?
Javascript button:
Aperx Class:
What am I dong wrong and how do I fix it?
regards,
ckellie
Changed field Opportunity_Line_Item__c to Quote_Item_Number__c and it is working just fine. Thank you very much kpeters
Good to hear ckellie! Please mark it as the solution if it solved your problem.
Hi
SFDC has introduced a new parameter "_CONFIRMATIONTOKEN' to avoid your trick so here is new JS code (not very nice for parsing part) that works well :
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
{!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js")}
// get confirmation token and set webform field
$.ajax({
url:"./oppitm/lineitemsort.jsp?id={!Opportunity.Id}",
contentType:"text/html",
xhrFields:{withCredentials:true}
}).done (
function(data){
key_start='id="_CONFIRMATIONTOKEN" value="';
key_end='"';
pos_start=data.indexOf(key_start);
pos_end=data.indexOf(key_end,pos_start+key_start.length);
confirmationtoken=data.substring(pos_start+key_start.length,pos_end);
//need to post a form to /oppitm/lineitemsort.jsp because this is how SFDC
//does it but there is not direct API to do the sorting (thus the awkward workaround)
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "/oppitm/lineitemsort.jsp");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", '_CONFIRMATIONTOKEN');
hiddenField.setAttribute("value", confirmationtoken);
form.appendChild(hiddenField);
var oppID = '{!Opportunity.Id}';
//call the apex web service to get the OLIs in the desired sort order for this opp
var result = sforce.apex.execute("customSort","MRsort",{oppID: oppID});
//set the id of the request to the opportunity ID
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'id');
hiddenField.setAttribute("value", '{!Opportunity.Id}');
form.appendChild(hiddenField);
//the name of the sorted OLI list that the JSP is expecting is "duel0"
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'duel0');
hiddenField.setAttribute("value", String(result));
form.appendChild(hiddenField);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'retURL');
hiddenField.setAttribute("value", '/{!Opportunity.Id}');
form.appendChild(hiddenField);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'cancelURL');
hiddenField.setAttribute("value", '/{!Opportunity.Id}');
form.appendChild(hiddenField);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'save_new_url');
hiddenField.setAttribute("value", '/oppitm/lineitemsort.jsp');
form.appendChild(hiddenField);
//set to save
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'save');
hiddenField.setAttribute("value", 'Enregistrer');
form.appendChild(hiddenField);
//need to do this so it works in IE
document.body.appendChild(form);
form.submit();
}
);
Thank you for alternate solution, it works great on custom JS button. However I have a custom VF page and need to call this code when user clicks "Save" button. I tried below code, but it won't work. Essentially, I think the issue is getting the confirmation token from VF page.
Thank you for your time in advance.
Hi guys!
I've exact the same problem as Mitesh and the problem is the ajax call returning with the authentification error already, so no token to be found there. Did anybody solve this for a call out of a VF-Page?
testSort = [Select oli.Id, oli.Line_Number__c,Descnickname__c
From OpportunityLineItem oli
Where oli.OpportunityId = :testOpp.id
ORDER BY oli.Line_Number__c];
system.test.startTest();
CustomSort controller = new CustomSort();
PageReference pageRef = new PageReference('/'+testOpp.id);
system.test.setCurrentPage(pageRef);
ApexPages.CurrentPage().getparameters().put('oppid', testOpp.id);
pageRef.getParameters().put('oppid', testOpp.id);
CustomSort.MRsort(testOpp.id);
System.assert(testSort != null);
system.test.stopTest();
Sort Quote Line Items and Create PDF Made Easy in Salesforce