function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raja JammulaRaja Jammula 

javascript error: invalid or unexpected token { can anyone please help

Javascript: I am getting Unexpected token error for below code can you please help:

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

var obj;
var task5;
var recordtypeid;
var followup;
var recordtypefol;
if("{!$Profile.Name}" == "TX1" || 
"{!$Profile.Name}"== "TX2"||
"{!$Profile.Name}"== "WX1"||
"{!$Profile.Name}"== "WX2"||
"{!$Profile.Name}"== "WX3"||
"{!$Profile.Name}"== "WX4"|| 
"{!$Profile.Name}" == "CC"){

obj='a1r';
}
else{
obj='00T';
}
alert(obj);

var url='/'+obj+'/e?CF00N50000002CzJi={!Account.Name}&CF00N50000002CzJi_lkid={!Account.Id}&retURL=/{!Contact.Id}&title=Call&who_id={!Contact.Id}&00N50000002D0zP={!User.Primary_Product__c}'
if(obj=="a1r")
{
url+='&followup=1&tsk5=call'
}

if(obj=="00T"){
if("{!$Profile.Name}" == "WI" && ("{!$UserRole.Name}"=="AS - E"||"{!$UserRole.Name}"=="AS - M"||"{!$UserRole.Name}"=="AS - T")){
task5="Meeting";
recordtypeid="0123B0000008tqK";
followup='';
recordtypefol="0123B0000008tqK";
}elseif("{!$Profile.Name}" == "WI Corporate Sales") {
task5="call";
recordtypeid="01250000000HiDD";
followup ="1";
recordtypefol="01250000000HiDD"; 
}else{
url+='&tsk5='+task5+'$tsk12=Completed'+'&RecordType='+recordtypeid+'&RecordType_fu='+recordtypefol+'&followup='+followup+'&tsk4={!TODAY()}'
}
}
else{
url+='&followup=1&tsk5=call'
}

window.parent.open(url, "_self");
Best Answer chosen by Raja Jammula
Asif Ali MAsif Ali M
already responded to your other post.
url+='&tsk4={!MONTH(TODAY())}/{!DAY(TODAY())}/{!YEAR(TODAY())}';

 

All Answers

Asif Ali MAsif Ali M
Add a space between else if statement. 
 
} else if("{!$Profile.Name}" == "WI Corporate Sales") {

 
Raja JammulaRaja Jammula
Thanks Asif Ali, but i am getting another "call not defined" for "a1r" for user in profile: WX2
URL not populating correctly for "00T" user and for all other users: Unable to Access Page
The value of the "id" 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. 

can you helpme where i am going wrong
 
Asif Ali MAsif Ali M
Seems like you are getting 2 different errors JS and SF. 
Send me the line# for JS error with full error message and for SF error send me the url (variable) value
Asif Ali MAsif Ali M
Also tell me the purpose of these params in your url
  1. CF00N50000002CzJi_lkid
  2. CF00N50000002CzJi
  3. 00N50000002D0zP
Raja JammulaRaja Jammula
URL: https://XXXX.my.salesforce.com/00T/e?CF00N50000002CzJi=C2PM&CF00N50000002CzJi_lkid=0015000001HxOaW&retURL=/0035000002plAz0&title=Call&who_id=0035000002plAz0&00N50000002D0zP=DC&tsk5=undefined$tsk12=Completed&RecordType=undefined&RecordType_fu=undefined&followup=undefined&tsk4=9/22/2017

Error:Unable to Access Page
The value of the "id" 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. 

URL:https://XXXX.my.salesforce.com/00T/e?CF00N50000002CzJi=C2PM&CF00N50000002CzJi_lkid=0015000001HxOaW&retURL=/0035000002plAz0&title=Call&who_id=0035000002plAz0&00N50000002D0zP=DC

When i am Logging in as a user with profile: WI and also with Role AS - E the URL is not populating correctly

When i am Logging in as a user with profile: WX2 it's throwing javascript error: "call not defined"

 
Raja JammulaRaja Jammula
CF00N50000002CzJi={!Account.Name}
CF00N50000002CzJi_lkid={!Account.Id} 
00N50000002D0zP={!User.Primary_Product__c}

this button is on contact: detail page button so we are pulling in related account and product related to the user. it's the custom button similar functionality to "Log a call" Standard button 
Raja JammulaRaja Jammula
the correct URL i need to pass:
if("{!$Profile.Name}" == "TX1" || 
"{!$Profile.Name}"== "TX2"||
"{!$Profile.Name}"== "WX1"||
"{!$Profile.Name}"== "WX2"||
"{!$Profile.Name}"== "WX3"||
"{!$Profile.Name}"== "WX4"|| 
"{!$Profile.Name}" == "CC")
URL:a1r /e?CF00N50000002CzJi={!Account.Name}&CF00N50000002CzJi_lkid={!Account.Id}&retURL=/{!Contact.Id}&title=Call&who_id={!Contact.Id}&00N50000002D0zP={!User.Primary_Product__c}&followup=1&tsk5=Call

if profile not equal to above profiles: 00T/e?CF00N50000002CzJi={!Account.Name}&CF00N50000002CzJi_lkid={!Account.Id}&retURL=/{!Contact.Id}&title=Call&who_id={!Contact.Id}&00N50000002D0zP={!User.Primary_Product__c}&followup=1&tsk5=Call

but i need to include different conditions on the above part "00T":
if("{!$Profile.Name}" == "WI" && ("{!$UserRole.Name}"=="AS - E"||"{!$UserRole.Name}"=="AS - M"||"{!$UserRole.Name}"=="AS - T"))
then&tsk5=Meeting and URL should not include followup

and if("{!$Profile.Name}" == "WI" && ("{!$UserRole.Name}"!="AS - E"||"{!$UserRole.Name}"!="AS - M"||"{!$UserRole.Name}"!="AS - T"))
then &followup=1&tsk5=Call but include Recordtypes &RecordType="01250000000HiDD"&RecordType_fu="01250000000HiDD"

that's my criteria and basically what i am trying to achieve
Asif Ali MAsif Ali M
Hi

I tested both scenarios you mentioned above and no error occurs for me. It might be something related to Data.
Can you send me the final url generated in both cases?


 
Raja JammulaRaja Jammula
Hi Asif, it's working nowi have another problem where i am using script in vf page and calling a button:

<script>
        function setLogcallURL(){
        var url='/00T/e?title=Call&who_id={!Contact.Id}&retURL=/{!Contact.Id}' 
        
        if("{!$Profile.Name}" == "WI" && ("{!$UserRole.Name}"=="AE - E"||"{!$UserRole.Name}"=="AE - W"||"{!$UserRole.Name}"=="AE - S")){ 
            url+='&tsk5=Meeting'; 
            url+='&tsk4={!TODAY()}'; 
            url+='&tsk12=Completed'; 
            url+='&RecordType=0120j0000008dlO'; 
            url+='&ent=Task'; 
        }else if("{!$Profile.Name}" == "WI Corporate Sales") { 
            url+='&tsk5=Call'; 
            url+='&followup=1'; 
            url+='&tsk4={!TODAY()}'; 
            url+='&RecordType=01250000000HiDD'; 
            url+='&RecordType_fu=01250000000HiDD'; 
        }else{ 
            url+='&followup=1'; 
            url+='&tsk5=Call'; 
        }
        window.open(url,"_self");
        }
    
    </script>
from vf page:
     <apex:commandButton value="Log a Call"  onclick="setLogcallURL()" rendered="{!contact.CSG_Status__c == 'Active'}"/>
when i click a button it's reloading the same page and not calling the url

when i change to window.open(url,'_blank'); then it loads the page in seperate tab.
And &tsk4={!TODAY()} it's not the populating the date correctly 
it's populating as: Tue Sep 26 00:00:00 GMT 2017 instead 09/26/2017

​can you let me know where i am going wrong here
 
Raja JammulaRaja Jammula
the same page issue is solved used "oncomplete" rather than "onclick" event and iam trying to solve date issue
Asif Ali MAsif Ali M
already responded to your other post.
url+='&tsk4={!MONTH(TODAY())}/{!DAY(TODAY())}/{!YEAR(TODAY())}';

 
This was selected as the best answer
Raja JammulaRaja Jammula
Thanks Asif that is working like a charm