Add custom onclick Javascript to skuid
Good morning! I am trying to add a OnClick JavaScript button we have in Salesforce to be available in skuid. The button is an Event custom list button that is available for Multi-Record Selection. I am not familiar with JavaScript so any help converting this process to Skuid is greatly appreciated!
Below is the OnClick JavaScript code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")}
var accountId = '{!Account.Id}';
var accountTerritory = '{!Account.Territory__c}';
var accountSalesRegion = '{!Account.Sales_Region__c}';
var accountSegment = '{!Account.Account_Segment__c}';
var accountOwner = '{!Account.Account_Executive__c}';
var newURL = sforce.apex.execute(
"AutomaticOppAssigment", "OpportunityAssignment",
{
acctIdInput:accountId,
acctTerritoryInput:accountTerritory,
acctSalesRegionInput:accountSalesRegion,
acctSegmentInput:accountSegment,
acctOwnerInput:accountOwner
});
parent.location.href = newURL;
Below is the OnClick JavaScript code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")}
var accountId = '{!Account.Id}';
var accountTerritory = '{!Account.Territory__c}';
var accountSalesRegion = '{!Account.Sales_Region__c}';
var accountSegment = '{!Account.Account_Segment__c}';
var accountOwner = '{!Account.Account_Executive__c}';
var newURL = sforce.apex.execute(
"AutomaticOppAssigment", "OpportunityAssignment",
{
acctIdInput:accountId,
acctTerritoryInput:accountTerritory,
acctSalesRegionInput:accountSalesRegion,
acctSegmentInput:accountSegment,
acctOwnerInput:accountOwner
});
parent.location.href = newURL;
Tagged:
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
I believe you should be able to call this from the Skuid page. Here are some tips to get you started:
1. The sforce.apex.execute() function is a function to call Apex using the AJAX toolkit in Salesforce. In order for this to work, you will need to include the AJAX toolkit URL (/soap/ajax/30.0/connection.js) within your Skuid page. To do this, go to the JavaScript tab in the page composer, add a new resource with a Resource Location of "External", and include the URL as the Resource URL.
2. Create a new JavaScript snippet that you can execute from a button in your Skuid page. To do this, create another JavaScript resource with a Resource Location of type "In-Line (Snippet)". You can give it whatever name you prefer (Example: AssignOpportunities). Your snippet code may look something like this: 3. Call this snippet from a Skuid button or action. You could do this either through a button/action type "Custom: Run Skuid Snippet" or through the Action Framework. To use the Actions Framework, specify a button/action type "Run Multiple Actions", and add an action of type "Run a Skuid JavaScript snippet".
Here is a post with more information on various ways to call Apex from Skuid:
https://community.skuid.com/skuid/topics/calling_apex_function
Also, here are some tutorials that may be helpful for you:
Action Framework http://help.skuid.com/m/supercharge-your-ui/l/239686-action-framework
Skuid Snippets http://help.skuid.com/m/11720/l/204699-introduction-to-skuid-snippets
I hope this is enough to get you started. Let me know if you have more questions specific to your use case.
Thanks!
Emily
The JS snippet posted above, and the steps outlined are exactly what we have in place currently. The issue is that the apex runs and redirects to a URL in salesforce, but we want the process to stay in skuid- possibility through a wizard component? I am just not sure how to pass the variables to the field editor in the wizard after the apex runs.
I created a new post that more accurately addresses the issue we are having:
https://community.skuid.com/skuid/topics/javascript-parameters-passed-to-field-in-wizard-component
Does your apex contain a hard coded redirect upon completion?
Also, make sure you are using apex.js not connection.js, which is included with Skuid.
I think the cause of the redirect is actually the line:
parent.location.href = newURL;
in the js. Sorry I missed that! You can just delete it or comment it out.
I'll go check out that other post now.