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
cjencjen 

Need help converting a javascript button with validation to a lightning component

This is the javascript we have for a button on the opportunity. Can anyone help with converting this to lightning, please?


if('{!Opportunity.Related_Contract__c}'!=''&&'{!Opportunity.Type_of_Contract__c}' != 'Addendum'){ 
alert("Sorry, a Contract record has already been created for this opportunity. You can view the Contract by clicking on the Related Contract link in the Contract/Amendment Details section."); 

else if('{!Opportunity.Related_Amendment__c}'!=''&&'{!Opportunity.Type_of_Contract__c}' == 'Addendum'){ 
alert("Sorry, an Amendment record has already been created for this opportunity. You can view the Amendment by clicking on the Related Amendment link in the Contract/Amendment Details section."); 


else if('{!Opportunity.Type_of_Contract__c}' == ''){ 
alert("Please enter a Type of Contract before requesting a Contract or Addendum."); 

else if('{!URLENCODE(Opportunity.Contact__c)}' == ''){ 
alert("Please enter a Contract Contact before requesting a Contract or Addendum."); 

else if(!('{!Opportunity.Type_of_Contract__c}'=='')&&'{!Opportunity.Has_Banker_PPE_Service__c}'>0&&('{!Opportunity.Cost_Per_Additional_User__c}'==''||'{!Opportunity.Users__c}'=='')){ 
alert("This opportunity has a Banker PPE service. Before requesting a Contract or Addendum, please provide the number of Users and the Cost per Additional User in the Contract Details section."); 

else if('{!Opportunity.Type_of_Contract__c}' == 'Addendum'){ 
window.open ( "/a4u/e?saveURL={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}&00N38000003rUFs={!Opportunity.Name}&CF00N38000003rUFn={!Opportunity.Name}&CF00N38000003rUFn_lkid={!Opportunity.Id}&CF00N38000003rUFd={!Opportunity.Related_Contract__c}&CF00N38000003rUFd_lkid={!Opportunity.Related_ContractId__c}","_top"); 

else{ 
window.open ( "/800/e?saveURL={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}&00N38000003Hm3a={!Opportunity.Type_of_Contract__c}&Name={!Opportunity.Name}&ctrc40={!Opportunity.Contract_Term__c}&00N38000003Hj9L={!Opportunity.Renewal_Term_months__c}&00N38000003Hm4E=1&CF00N50000002bj33={!Opportunity.Name}&CF00N50000002bj33_lkid={!Opportunity.Id}&ctrc15=New&ctrc7={!URLENCODE(Opportunity.Account_Name_TEXT__c) }&ctrc7_lkid={!Opportunity.AccountId}","_top"); 
}
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

I trust you are doing very well.

You can use Lightning Experience Configuration Converter to convert JavaScript buttons to lightning. Please refer to the below links which might help you further with the above issue.

https://developer.salesforce.com/blogs/2018/06/convert-javascript-buttons-to-lightning-friendly-alternatives-with-the-lightning-experience-configuration-converter.html

https://help.salesforce.com/articleView?id=lcc_considerations.htm&type=5

https://developer.salesforce.com/blogs/developer-relations/2016/09/take-the-first-steps-ways-you-can-replace-javascript-buttons.html

There are other options also to replace the javascript button in lightning. You can use Quick Actions, Custom Buttons, or Apex. Go through this trailhead module to understand the alternatives available:
Lightning Alternatives to JavaScript Buttons (https://trailhead.salesforce.com/en/modules/lex_javascript_button_migration)

Also, Please refer to the below link:

https://www.bayforce.com/wp-content/uploads/2017/10/Bayforce-JavaScript-Lightning-Experience-White-Paper.pdf

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas