Overview
SmartSuite's scripting feature empowers you to automate tasks, enhance data analysis, and create custom workflows. With scripting, you can:
- Create a script to analyze records in a view and calculate a custom metric, storing the result in a specified field.
- Validate data integrity by identifying records that don't comply with specific rules (e.g., ensuring that no individual is assigned more than three high-priority tasks at once).
- Combine information from duplicate records based on custom criteria, ensuring your data remains clean and consolidated.
- Retrieve data from external APIs, such as live stock prices or weather updates, and save the results to relevant fields in your records.
- Prompt the user for input, such as a project title, and automatically generate all associated records, such as tasks and deadlines, based on a predefined template.
Getting Started
To begin scripting in SmartSuite, a basic understanding of JavaScript is recommended. You can explore example scripts in our documentation or visit our community forum for inspiration and guidance.
In your script, you can use any part of the JavaScript standard library, and when creating a script for an interactive element in SmartSuite (such as the Custom Code widget or a button action) you can create and update HTML to present data or allow the user to interact with your script.
SmartSuite's scripting engine also provides specific methods for accessing and updating data in your records. You will find documentation of these methods and their data structures on this site.
To reference the SmartSuite scripting SDK, you need to point to window.SmartSuite.[method] in your script. For example, to get the current Member you would call the getCurrentMember function like this:
<script>
window.SmartSuite.get_current_member().then((res) => {
console.log('member res =>>>', res);
});
</script>
Because you can also include HTML in your script (essentially a Web page displayed in an iFrame), enclode your script in script tags, as shown above. You can use standard javascript selectors to interact with HTML elements on the script's page. An example:
<!DOCTYPE html>
<html>
<head>
<title>SmartSuite Member Info</title>
<style>
#result {
margin: 20px;
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f5f5f5;
font-family: monospace;
white-space: pre-wrap;
}
.error {
color: red;
}
</style>
</head>
<body>
<h1>Current Member Information</h1>
<!-- Result will be displayed here -->
<div id="result">Loading...</div>
<script>
// Wait for the page to load
document.addEventListener('DOMContentLoaded', function() {
// Get reference to the result div
const resultDiv = document.getElementById('result');
// Call the SmartSuite API to get current member info
window.SmartSuite.get_current_member()
.then((res) => {
// Format the response as pretty-printed JSON
resultDiv.textContent = JSON.stringify(res, null, 2);
})
.catch((error) => {
// Display any errors that occur
resultDiv.textContent = 'Error fetching member data';
resultDiv.classList.add('error');
console.error('Error:', error);
});
});
</script>
</body>
</html>
Additional Resources
- MDN JavaScript Guide: A comprehensive introduction to JavaScript fundamentals.
- Codecademy Introduction to JavaScript: A free interactive course for learning JavaScript basics.
- Community Forum: Connect with other SmartSuite users to share ideas, showcase scripts, and get support for your scripting needs.