+ Start a Discussion
Osiris77706Osiris77706 

JavaScript Error on custom button.

Hello,



My organization is working with Cincom Systems Inc. and have installed the
"Cincom Sales and Product Configurator" From the app Exchange. We are
developing a configurator for our sales team to use in conjunction with
salesforce. The Package abve comes with a few custom buttons that are used on
the Quote object and Quote Line Item object. One of these buttons is throwing a
javascript error. Cincom was unable to assist me in figuring out exactly why
such an error would occour, but they were able to assist me in debugging the
issue down to a particular line of code where the error originated., the code
behind the button, and the particular line the error originates at below:



HERE is the code behind the button.



{!requireScript("/soap/ajax/22.0/connection.js")}



function GetCRMConfiguratorURL() 

{

var queryResult = sforce.connection.query("SELECT C_SPC__Protocol__c,
C_SPC__ServerName__c, C_SPC__Directory__c FROM
C_SPC__CRM_Configurator_Setup__c"); 

return (queryResult != null && queryResult.size > 0) ?
queryResult.getArray("records")[0].get("C_SPC__Protocol__c")
+ "://" + queryResult.getArray("records")[0].get("C_SPC__ServerName__c")
+ "/" +
queryResult.getArray("records")[0].get("C_SPC__Directory__c")
: "http://localhost/CRMConfigurator";


} 



function GetDefaultApplicationId() 

{

window.alert("Starting GetDefaultApplicationID");

window.alert("recordIds[0].substring(0,15) = " +
recordIds[0].substring(0,15) );

**********************************************************************************************************************************************

var queryResult = sforce.connection.query("SELECT PricebookEntryId FROM
QuoteLineItem WHERE Id = '" + recordIds[0].substring(0,15) +
"'");

***********************************************************************************************************************************************

window.alert("PriceBook queryResult.size=" + queryResult.size);

var pricebookEntryId = (queryResult.size > 0) ?
queryResult.getArray("records")[0].get("PricebookEntryId")
: null;

if (pricebookEntryId == null) return null;

queryResult = sforce.connection.query("SELECT Product2Id FROM
PriceBookEntry WHERE Id = '" + pricebookEntryId + "'");

window.alert("Product2 ID queryResult.size=" + queryResult.size);

var productId = (queryResult.size > 0) ?
queryResult.getArray("records")[0].get("Product2Id") :
null;

if (productId == null) return null;

queryResult = sforce.connection.query("SELECT
C_SPC__ProductApplicationId__c FROM Product2 WHERE Id = '" + productId +
"'");

window.alert("product applicationID queryResult.size=" +
queryResult.size);

var productApplicationId = (queryResult.size > 0) ?
queryResult.getArray("records")[0].get("C_SPC__ProductApplicationId__c")
: null;

if (productApplicationId == null) return null;

var today = GetDateToday();

queryResult = sforce.connection.query("SELECT Id,
C_SPC__BeginEffectiveDate__c FROM C_SPC__Application__c WHERE
C_SPC__ProductApplicationId__c = '" + productApplicationId + "' ORDER
BY C_SPC__RevisionNumber__c DESC");

window.alert("Application query queryResult.size=" +
queryResult.size);

for (var i = 0; i < queryResult.size; i++)

{

var beginEffectiveDate =
queryResult.getArray("records")[i].get("C_SPC__BeginEffectiveDate__c");

if (beginEffectiveDate == null || beginEffectiveDate == '' ||
beginEffectiveDate <= today)

return queryResult.getArray("records")[i].get("Id");

}

return null;

}



function GetDateToday() 

{

var dateToday = new Date();

var monthToday = dateToday.getMonth() + 1; if (monthToday < 10) monthToday =
"0" + monthToday;

var dayToday = dateToday.getDate(); if (dayToday < 10) dayToday =
"0" + dayToday;

return dateToday.getFullYear() + '-' + monthToday + '-' + dayToday;

}



window.alert("Starting");

var recordIds = {!GETRECORDIDS($ObjectType.QuoteLineItem)};

if (recordIds == null || recordIds.length ==0)

alert("Please select a quote line item.");

else if (recordIds.length > 1)

alert("Please select only one quote line item.");

else

{

var queryResult = sforce.connection.query("SELECT C_SPC__ApplicationId__c
FROM C_SPC__ConfigurationDna__c WHERE C_SPC__QuoteLineItemId__c = '" +
recordIds[0].substring(0,15) + "'");

window.alert("recordIds[0].substring(0,15) NEW = " +
recordIds[0].substring(0,15) );

window.alert("queryResult.size= " + queryResult.size);

var applicationId = (queryResult.size > 0) ?
queryResult.getArray("records")[0].get("C_SPC__ApplicationId__c")
:

GetDefaultApplicationId();

window.alert("Aplication ID");

if (applicationId == null || applicationId == '')

alert("The quote line item Product is not configurable.");

else

window.parent.location.href = GetCRMConfiguratorURL() +
'/CRMConfiguratorPage.aspx?CrmType=2&QuoteLineItemId='+recordIds+'&ApplicationId='+applicationId+'&SessionId={!$Api.Session_ID}&ServerURL={!$Api.Partner_Server_URL_220}&ReturnURL='+window.parent.location.href;

window.alert("window.parent");

}

 

 






HERE is the line of code that is throwing the error:

var queryResult = sforce.connection.query("SELECT PricebookEntryId FROM
QuoteLineItem WHERE Id = '" + recordIds[0].substring(0,15) +
"'");

 

 




In order to see the line in context, it is denoted by lines of '*' in the code
above.



The error is as follows:



A Problem with the OnClick JavaScript for this button or link was encountered.

{faultcode:'sf:INVALID_TYPE', faultstring:'INVALID_TYPE:sObject type
'QuoteLineItem' is not supported.',
detail:{exceptionCode:'INVALID_TYPE',exceptionMessage:'sObject type
'QuoteLineItem' is not supported.', row:'-1',},},}