Delete Quote Line Items using JavaScript

By | June 7, 2017

We all are much familiar with Quote mechanism provided by SAGE CRM. We can manage quotes for an opportunity and also further can convert it to order for our customers. This functionality allows us to add Line Items or Products against it. In this blog, I will explain how we can delete line item record from the quote using JavaScript.

New Stuff: Respond to the growing complexities: Explore the new GUMU™ connector for Sage X3 – Sage CRM Integration

The Standard CRM system gives the provision to delete the Line items added against the Quote by clicking on the added Product hyperlink and then clicking the Delete button. To avoid such long process we have incorporated check boxes against each line item which will help the user to delete single or multiple line items at one go.

To achieve this, write the below Code to your Custom Page and call the function on the page load.

function AddCheckBox()
{
if(crm.grids(“0”))
{
crm.grids(“0”).addColumn({index:0,columnName: “Select”});
var value = function() {
var colText = this.getCellText(this.currentRow,this.columnNames.indexOf(“prod_name”));
//’get company id from 1 column link
var colDes = this.columnNames.indexOf(“prod_name”)
var cellRef = this.getCellHtml(this.currentRow,colDes);
var sAttr=new String($(cellRef).attr(“onclick”));
if(sAttr==”null” ||sAttr==”” || sAttr==”undefined”)sAttr=””;
var cellProdLineItemid =””;
if(sAttr!=””)
{
cellProdLineItemid = crm.getArg(“Key72”, $(cellRef).attr(“onclick”).split(“window.location “)[1]);
if(cellProdLineItemid==”null” ||cellProdLineItemid==”” || cellProdLineItemid==”undefined”)
{
cellProdLineItemid = crm.getArg(“Key72”, $(cellRef).attr(“onclick”));
if(cellProdLineItemid==”null” ||cellProdLineItemid==”” || cellProdLineItemid==”undefined”)cellProdLineItemid=””;
}
}
if(cellProdLineItemid!=””)
cellProdLineItemid = cellProdLineItemid;
else
cellProdLineItemid = “0”;
return cellProdLineItemid;
}
crm.grids(“0″).addCells({index:0,type:”checkbox”, value : “0”,id: value, disabled: false, checked : false ,
click : function(){console.log(“This is a test check box”);}});//OpenQuoteItems($(this).attr(“id”));
}
}
function OpenQuoteItems()
{
var sLineItemID= “”;
$( “input:checked” ).each(function() {
var sId=$(this).attr(“id”);
if(sLineItemID==””)
sLineItemID=sId
else
sLineItemID+=”,”+sId
});
if(sLineItemID!=””)
{
var sURL = GetCRMPath();
sURL +=”/CustomPages/QuoteItems/QuoteItemsDelete.asp?SID=”+GetCurrURLValue(“SID”)+”&Key58=”+sLineItemID+”&QuIt_LineItemID=”+sLineItemID+””;
window.location.href = sURL;
}
else
alert(‘Atleast Check one Checkbox !!!’);
}
function GetCurrURLValue(name)
{
var winURL = window.location.href;
var queryStringArray = winURL.split(“?”);
var queryStringParamArray = queryStringArray[1].split(“&”);
var nameValue = null;
for ( var i=0; i<queryStringParamArray.length; i++ )
{
queryStringNameValueArray = queryStringParamArray[i].split(“=”);
if ( name == queryStringNameValueArray[0] )
{
nameValue = queryStringNameValueArray[1];
}
}
return nameValue;
}
function GetCRMPath()
{
var sPageURL = new String(document.URL);
var sURL = ”;
var iEndChar=0;iStartChar=0;
sPageURL = sPageURL.toLowerCase();
iEndChar = sPageURL.indexOf(‘/eware’);
if (iEndChar != -1)
{
//find the first ‘/’ before this
iStartChar = sPageURL.substr(0,iEndChar);
iStartChar++
sURL = sPageURL.substring(iStartChar,iEndChar);
}
return sURL;
}
Also prepare the .asp page with below code. This code will help you to delete the record from Quote.
<!–#include file =”../eWare.js” –>
<%
var LineItemID=””;
if( Request.QueryString(“QuIt_LineItemID”) != “” ){
LineItemID = Request.QueryString(“QuIt_LineItemID”);
}else{
LineItemID = Request.QueryString(“Key58”);
}
LineItemID=new String(LineItemID);
var sItemID=LineItemID.split(“,”);
for(var indexitem=0;indexitem<sItemID.length;indexitem++)
{
var sOrderquoteid=””;
var sLinenumber =””
var sQuoteTotal=””;
var objQuoteItems = eWare.FindRecord(“QuoteItems”,”QuIt_LineItemID IN (‘”+sItemID[indexitem]+”‘)”);
if(!objQuoteItems.eof)
{
sLinenumber = new String(objQuoteItems(“quit_linenumber”));
if(sLinenumber==”undefined” || sLinenumber==””)sLinenumber = 0;
sOrderquoteid = new String(objQuoteItems(“QuIt_orderquoteid”));
if(sOrderquoteid==”undefined” || sOrderquoteid==””)sOrderquoteid = 0;
var sql = ” UPDATE QuoteItems SET quit_linenumber = (quit_linenumber -1) WHERE quit_linenumber > “+sLinenumber+” AND quit_linenumber >= 0 AND quit_orderquoteid=”+sOrderquoteid+” AND quit_DELETED IS NULL “;
eWare.ExecSql(sql);
objQuoteItems(“quit_DELETED”) = 1;
objQuoteItems.SaveChanges();
var oRec= eWare.CreateQueryObj(“SELECT SUM(quit_quotedpricetotal) AS Total FROM QuoteItems WHERE QuIt_Deleted IS NULL AND QuIt_orderquoteid=”+sOrderquoteid );
oRec.selectSQL();
if (!oRec.eof)
{
sQuoteTotal = new String(oRec(“Total”));
if(sQuoteTotal==”undefined” || sQuoteTotal==””)sQuoteTotal = 0;
}
var sql = “Update Quotes set quot_GrossAmt =”+sQuoteTotal+”,quot_NettAmt=”+sQuoteTotal+” WHERE Quot_OrderQuoteID=”+sOrderquoteid;
Updatequery = eWare.CreateQueryObj(sql);
Updatequery.ExecSql();
//objQuoteItems.DeleteRecord = true;
//objQuoteItems.SaveChanges();
}
}
var strBackURL=eWare.URL(523);
Response.Redirect(strBackURL);
%>
Add below script on Custom Content Quote Summery screen to add Delete button and add checkbox.
<script>
crm.ready(function() {
crm.addButton(“..\\Themes/Img/Color1/Buttons/Delete.gif”,”button”,”Delete Line Item”,{“index”: 3,”href”: “javascript:OpenQuoteItems();”});
AddCheckBox();
});
</script>
After applying this changes, you will be able to see the check boxes against each line item record. Click the checkbox and click on “Delete Line Item” button. The record will be remove from the quote.
About Us
Greytrix a globally recognized Premier Sage Gold Development Partner is a one stop solution provider for Sage ERP and Sage CRM needs. Being recognized and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third party add-on development and implementation expertise.

Greytrix has some unique integration solutions for Sage CRM with Sage ERPs (Sage Enterprise Management (Sage X3), Sage Intacct, Sage 100Sage 500 and Sage 300).We also offer best-in-class Sage ERP and Sage CRM customization and development services to Business Partners, End Users and Sage PSG worldwide. Greytrix helps in migrating of Sage CRM from Salesforce | ACT! | SalesLogix | Goldmine | Sugar CRM | Maximizer. Our Sage CRM Product Suite includes Greytrix Business Manager, Sage CRM Project Manager, Sage CRM Resource Planner, Sage CRM Contract Manager, Sage CRM Event Manager, Sage CRM Budget Planner, Gmail Integration, Sage CRM Mobile Service Signature and Sage CRM CTI Framework.

Greytrix is a recognized Sage Rockstar ISV Partner for GUMU™ Sage Enterprise Management – Sage CRM integration also listed on Sage Marketplace.

For more information on our integration solutions, please contact us at [email protected]. We will be glad to assist you.