0

I'm trying to convert a JS button into lightning.

    {!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 
var numTCs = {!Sales_Toolkit__c.Number_of_Theme_Conversions__c}; 
var curStatus = '{!Sales_Toolkit__c.Current_Status__c}'; 

if(numTCs == 0) { 
alert('You must have at least one game title added before submitting this configuration.'); 
} else { 

var sID = '{!$Api.Session_ID}'; 
var ddpIds = '{!IF(Sales_Toolkit__c.Is_Ticket_Created__c=='False', 'a4n1O0000008gHA', 'a4n1O0000008gHB')}'; 
var eID = '{!Sales_Toolkit__c.Id}'; 
window.location.href = '/apex/loop__looplus?eid=' + eID + '&sessionid=' + sID + '&ddpIds=' + ddpIds + '&autorun=true'; 
}

It's a button to retrieve some of the current records info, session ID, and then push to a application called drawloop which then creates an attachment on the record.

Originally i just pushed all the code into a Visual Force Page and used that to create an action. But that doesn't work on the Mobile app which is the problem.

I've done this on the component end

<aura:component implements="force:lightningQuickAction,force:hasRecordId,force:hasSObjectName" >
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="Sales_Toolkit__c" type="String" />
     <lightning:button label="Test LComponent Submit Blue" 
        onclick="{!c.myaction}" />  
</aura:component>

But back to the JS, how do i refer to objects and their associated fields? API session ID? Google is failing me, i know i'm probably not asking it the right way.

When i copypasta the JS into the Controller (Except the requirescript) i instantly get "Parsing error: Unexpected token !" on line 5

EDIT

({
    myAction : function(component, event, helper) {


var numTCs = component.get(Sales_Toolkit__c.Number_of_Theme_Conversions__c); 
var curStatus = component.get(!Sales_Toolkit__c.Current_Status__c); 

if(numTCs == 0) { 
alert('You must have at least one game title added before submitting this configuration.'); 
} else { 

var sID = '{!$Api.Session_ID}'; 

**var ddpIds = '{!IF(Sales_Toolkit__c.Is_Ticket_Created__c=='False', 'a4n1O0000008gHA', 'a4n1O0000008gHB')}';** 

var eID = '{!Sales_Toolkit__c.Id}'; 
window.location.href = '/apex/loop__looplus?eid=' + eID + '&sessionid=' + sID + '&ddpIds=' + ddpIds + '&autorun=true'; 
}

    }
})

Did the above, now "Parsing Error: unexpected token False" under the !If(Sales_Toolkit__c portion marked above with **

EDIT 2: anyone know how to do

window.location.href = '/apex/loop__looplus?eid=' + eID + '&sessionid=' + sID + '&ddpIds=' + ddpIds + '&autorun=true';

a page redirect like that one...without actually having it affect the user? Like doing it to a pseudo user in apex? Basically that URL redirect takes those Vars and with the autorun starts an application called drawloop which creates an attachment for the record.

0

You cannot directly copy paste the JS in your existing VF page to a controller JS for a Lighting Component.

If I understand your question, then you are looking for getting the values which exist currently in the existing JS as in your Lightning Component's controller JS function myAction on click of the button.

You will need to utilize the init event here to be able to get the values related to that particular record. You will need to perform at least the following things:

  1. Declare respective aura:attributes on your component which will contain values e.g., Sales_Toolkit__c.Number_of_Theme_Conversions__c and from other fields
  2. Utilize init to fetch the required values from the record by performing a server call and then set the respective aura:attributes
  3. Then on click of myAction, you will be then able to fetch all those values back in your JS function by getting the values from the respective attributes

Below are some resources which will be helpful here:

  • Yes i'm trying to get field values of the current record into the JS controller, including the session ID. Then i'm trying to run checks on those values IE if one var ==0, or if one var (which is a bool) == false. Then i'm trying to do a URL redirect, to start a SFDC integrated application called drawloop. The url takes different record variables from the current record to create. Combined with autorun the application then generates an attachment and adds that to the current record. '/apex/loop__looplus?eid=' + eID + '&sessionid=' + sID + '&ddpIds=' + ddpIds + '&autorun=true'; – ensir Mar 20 at 20:22
  • For getting those values, as mentioned in the answer, you will need to make a server trip. Once you get those values, set those on attributes on component and utilize it elsewhere in your any of the JS functions. I am not sure what your loop__looplus VF page does, but if you need to redirect to a URL, you will need to use lightning:navigation for this purpose. I will recommend to go through the resources mentioned and that should help you here. – Jayant Das Mar 20 at 20:32
  • aahh i now see clearly thank you! The URL doesn't so much redirect as it runs a SFDC app-exchange application, hence the 'autorun' that generates a PDF file to attach to the current record. it doesn't have to redirect the user so much as just run in the background. but that's something i'll figure out later. – ensir Mar 20 at 20:38

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.