+ Start a Discussion
Santosh Reddy9989Santosh Reddy9989 

How to change the price book of quote ?

There are 2 pricebooks in our org. I have created one List Button using this URL:
/_ui/sales/quote/lineitem/ChooseQuotePricebook/e?id={!Quote.Id}

I am able to change the pricebook If quote didn't contain any lineitems. But when quote already have lineitems then i am getting below error.

Unable to Access Page
The value of a parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information. 


Thanks,
Santosh Reddy
Best Answer chosen by Santosh Reddy9989
DevADSDevADS
Becuase there are lines associated with quote so you won't be able to delete it.

You can delete the lines on the custom button click using Ajax toolkit and redirect to Pricebook Selection page. Refer below code -
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}

//create an example account
var quotelines = new sforce.SObject("QuoteLineItem");
var query = "select id from QuoteLineItem WHERE quoteId="+"'"+'{!Quote.Id}'+"'";
var queryResponse = sforce.connection.query(query);
var records = queryResponse.getArray("records");
var arrayIds = new Array();
for(var i=0;i<records.length;i++){
    arrayIds.push(records[i].Id);
}

var delResult = sforce.connection.deleteIds(arrayIds);
window.open('/_ui/sales/quote/lineitem/ChooseQuotePricebook/e?id={!Quote.Id}&retURL=%2F{!Quote.Id}','_self');
Hope this answers your question. Post here if you have any further questions and close this thread by marking "Best Answer" whichever helped you to resolve your problem.

Happy Coding!!

All Answers

DevADSDevADS
Hey Santosh,

The process eventually going to change the Pricebookd2Id on Quote. You can chane the Pricebook2Id if there are any lines associated with it. If you want to add new products to the quote from different pricebook then You need to delete all the existing lines first and insert new lines.

Hope this helps.

Happy Coding!!
Santosh Reddy9989Santosh Reddy9989

When I try to change I got this alert
User-added image
After pressing that Ok button i got that error message.

It was not an issue If that process deletes the existing line items. But I want to change pricebook of the quote which already have line items.

Thanks,
Santosh Reddy
 
DevADSDevADS
Becuase there are lines associated with quote so you won't be able to delete it.

You can delete the lines on the custom button click using Ajax toolkit and redirect to Pricebook Selection page. Refer below code -
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}

//create an example account
var quotelines = new sforce.SObject("QuoteLineItem");
var query = "select id from QuoteLineItem WHERE quoteId="+"'"+'{!Quote.Id}'+"'";
var queryResponse = sforce.connection.query(query);
var records = queryResponse.getArray("records");
var arrayIds = new Array();
for(var i=0;i<records.length;i++){
    arrayIds.push(records[i].Id);
}

var delResult = sforce.connection.deleteIds(arrayIds);
window.open('/_ui/sales/quote/lineitem/ChooseQuotePricebook/e?id={!Quote.Id}&retURL=%2F{!Quote.Id}','_self');
Hope this answers your question. Post here if you have any further questions and close this thread by marking "Best Answer" whichever helped you to resolve your problem.

Happy Coding!!
This was selected as the best answer