1

i have a Java script button that is throwing an error message but is still working. Its only throwing this error for some users so I believe its about permissions but its not obvious what it is? I wondered if anyone recognises this?

enter image description here

Here is the button script if that helps:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 

var subMirrorId = '{!OpportunityLineItem.Opportunity_Product_MirrorId__c}'; 

if(subMirrorId == null || subMirrorId == ''){ 

var oppProduct = new sforce.SObject("OpportunityLineItem"); 
var oppProdMirror = new sforce.SObject("Opportunity_Product_Mirror__c"); 
var mirrorLookup = '{!OpportunityLineItem.Opportunity_Product_MirrorId__c}'; 

oppProduct.Id = '{!OpportunityLineItem.Id}'; 

var queryRes = sforce.connection.query("Select UnitPrice, Quantity, TotalPrice, Product2Id, CurrencyIsoCode, SB_Quantity__c, Segment_Index__c, Description, Start_Date__c, End_Date__c, OpportunityId From OpportunityLineItem Where Id = '" + oppProduct.Id + "' LIMIT 1"); 

var records = queryRes.getArray("records"); 

oppProdMirror.Quantity__c = records[0].Quantity; 
oppProdMirror.Sales_Price__c = records[0].UnitPrice; 
oppProdMirror.Opportunity_Product_Id__c = '{!OpportunityLineItem.Id}'; 
oppProdMirror.Product__c = records[0].Product2Id;
oppProdMirror.Opportunity__c = records[0].OpportunityId;
oppProdMirror.Total_Price__c = records[0].TotalPrice;
oppProdMirror.CurrencyIsoCode = records[0].CurrencyIsoCode;
oppProdMirror.SBQQ_Quantity__c = records[0].SB_Quantity__c;
oppProdMirror.Description__c = records[0].Description;
oppProdMirror.Segment_Index__c = records[0].Segment_Index__c;
oppProdMirror.Start_Date__c= records[0].Start_Date__c;
oppProdMirror.End_Date__c = records[0].End_Date__c;

var oppProductMirrorInsertRes = sforce.connection.create([oppProdMirror]); 


if(oppProductMirrorInsertRes[0].getBoolean("success")){ 
oppProduct.Opportunity_Product_Mirror__c = oppProductMirrorInsertRes[0].id; 
var oppProdUpdRes = sforce.connection.update([oppProduct]); 

if(oppProdUpdRes[0].getBoolean("success")){ 

window.top.location.href = '/' + oppProductMirrorInsertRes[0].id 
} 

else{ 
alert('Error creating sub item container: ' + oppProdUpdRes[0]); 
} 
} 

else{ 
alert('Error creating sub item container: ' + oppProductMirrorInsertRes[0]); 
} 

} 

else{ 
window.top.location.href = '/' + subMirrorId; 
}
Description 
0

One problem is that you are using the same message for two different operations so it would be worth changing the code to something like:

var oppProductMirrorInsertRes = sforce.connection.create([oppProdMirror]); 
if (oppProductMirrorInsertRes[0].getBoolean("success")){ 
    oppProduct.Opportunity_Product_Mirror__c = oppProductMirrorInsertRes[0].id; 
    var oppProdUpdRes = sforce.connection.update([oppProduct]); 
    if(oppProdUpdRes[0].getBoolean("success")){ 
        window.top.location.href = '/' + oppProductMirrorInsertRes[0].id 
    } 
    else{ 
        alert('Error updating OpportunityLineItem:' + oppProdUpdRes[0]); 
    } 
} 
else{ 
    alert('Error creating Opportunity_Product_Mirror__c:' + oppProductMirrorInsertRes[0]); 
}

Given that the error only happens for some users, it is very likely to be a difference in profiles (or permission sets). Examine the object and field level access rights for Opportunity_Product_Mirror__c (and OpportunityLineItem) for profiles of users where it doesn't work. You then need to consider if the profiles are wrong or if it is legitimate that these profiles should not allow this operation; if it is the latter you should improve the error message reported to look less like a failure and more like a normal condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.