2

OI have a field called qualification score to validate lead before converted when qualification score <=60.

But qualification score is a string it will be like 5%,60% or Something like x%.

So, I need to convert in to an integer and validate.

But I am getting this error:

missing ; before statement

Please let me know where i missed it.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
String ourString = Lead.Qualification_Score__c;
String[] stringCharacters = ourString.split('%');
var child;
if(stringCharacters.length==1)
{
child = stringCharacters[0];
}
if(stringCharacters.length>1)
{
child =stringCharacters[0]+stringCharacters[1];
}
Integer d = Integer.ValueOf(child);
if(d<=60)
{
alert("Lead is not enough to qualify");
}
else{
window.open('https://cs57.salesforce.com/lead/leadconvert.jsp?retURL={!Lead.Id}&id={!Lead.Id}&_CONFIRMATIONTOKEN=VmpFPSxNakF4Tnkwd05DMHhObFF4TlRveE1Eb3hNUzQzTURGYSxoN2xDU05yM1FLVTZRb0x6bVJzaHMzLE4yWTBNVEJt&common.udd.actions.ActionsUtilORIG_URI=%2Flead%2Fleadconvert.jsp');
}
  • Is that qualification_score__c is percent field? – Santanu Boral Apr 13 '17 at 16:21
  • No it is a string field and we are calculating through apex with our criteria – Pavan tej Apr 13 '17 at 16:25
  • Is this JavaScript or Apex...? This isn't quite valid either way. – sfdcfox Apr 13 '17 at 16:47
  • Sorry i am new to javascript i thought it works but i dont know where i missed it. – Pavan tej Apr 13 '17 at 16:48
3

In a JavaScript button, it would be:

var score = parseInt("{!Lead.Qualification_Score__c}");
if(score<60) {
    alert("The score is too low");
} else {
    window.open("{!URLFOR($Action.Lead.Convert, Lead.Id, [id=Lead.Id], true)}");
}

Use parseInt to read the value. Use URLFOR for the correct (domain-agnostic) URL.

  • Really you are life saver it works like as expected – Pavan tej Apr 13 '17 at 16:54
  • @SantanuBoral JavaScript's parseInt simply reads digits until it finds a non-digit and stops. Feel free to read more on MDN parseInt. – sfdcfox Apr 13 '17 at 17:07
0

One You have declared var child inside the for loop and using it outside the loop. So declare the variable before the for loop.

two Since the stringCharacters list will always have the correct value at index 0, you can directly use it instead of looping through it.

var child = stringCharacters[0] ;

Just doing this will serve your purpose instead of a for loop.

  • I am getting same error updated my code check once and let me know if i missed anything – Pavan tej Apr 13 '17 at 16:41
0

You have mixed up apex with javascript.

There are no such String or Integer declarations in javascript.

Since qualification score is a string it will be like 5%,60% or Something like x%, so you have to trim off the % from end.

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ourString = {!VALUE( MID(Lead.Qualification_Score__c, 0, LEN(Lead.Qualification_Score__c)-1))};
if(ourString<=60)
{
    alert("Lead is not enough to qualify a lead");
}
else{
    window.open("{!URLFOR($Action.Lead.Convert, Lead.Id, [id=Lead.Id], true)}");
}

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.