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 

convert javascript button to lightning

Hi, we wnat to migrate to lightning but one of our issues is the use of javascript and validation. Can anyone show be how to get a button or action in Lighting for the following? I have read articles, but we validate fields with javascript and also determine what kind of record to create based on picklist selection. Please help if possible, thanks!

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('{!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");
}
Raj VakatiRaj Vakati
Try to use this tool  Lightning Experience Configuration Converter which generates code for you . Refer this post "JavaScript Buttons and Make Room for the Lightning Experience Configuration Converter! (Admin blog post)"



https://lightning-configuration.salesforce.com/

 
cjencjen
Hi, i tried the Configuration Converter. the above converted to Lightning Component (Partial). But when added to the page layout, and clicking the button. Get a pop up window that says - Sample Lightning Componet Action which is a link that takes you too https://github.com/developerforce/LEXComponentsBundle . there is also a button on the popup that says Accept and clicking it just seems to close the window. So, any ideas what i did wrong in the conversion process?
Raj VakatiRaj Vakati
You can able to modify the generated code ..  Edit the component and make changes