Overview
This guide provides step-by-step examples for running a function from a custom app and an automation in Rippling.
Custom app - custom object detail view
In this example, we're going to build a function that consolidates three actions into one, which streamlines the sign-up process for the end user. They will only need to perform a single action and will not be required to enter information (e.g., name) that was previously collected and already exists in Rippling.
We can do this by by calling the function from the list or detail view of a custom object. Here we have a custom app called Class Manager that allows employees to sign up for training classes.
The current process for signing up for a class is for the user to select the class, click the Add Class Signup button, and manually enter their information to create a sign up record.


We can use a function to make this process quicker and more seamless for the user. Let's start by instantiating the Rippling Javascript SDK and adding our bearer token. The token is saved in our custom settings, so we can access it using the following code:
const token = context.settings["my_api_key"];
const ripplingSDK = new RipplingSDK({ bearerToken: token });
Next, let's add the logic for creating the class signup record. We can do this by creating an HTTP request to the custom objects endpoint.
const signupResponse = await ripplingSDK.customObjects.records.create("class_signup__c", {"owner_role": event.current_user, "class__c": event.record_id});
We need to send parameters in our request to let the API know what information to include in the class sign up record. The first parameter is the custom object API name. We can find this by looking at the custom object.

The second parameter is a JavaScript object with a list of key value pairs that match the field API names in our custom object. This list tells the API what values to assign to the fields in the new class sign up record. These can be found under the Fields tab in the custom object.

We want to pass in the user and the class information, and we can find both in the FunctionEvent.
event.current_user gives us the logged in user and event.record_id gives us the ID for the class that is currently selected.
It's also a good idea to add some logging here in case we need to see the response from the API for testing or troubleshooting.
console.log(JSON.stringify(signupResponse))
Now that the logic is in place, we can indicate how we want the function to respond to the user's input. If the user is signed up successfully, we want to display a success message. The message can be customized here, and the 200 response code will make the message appear in a green box.
return new FunctionResponse({
body: {},
statusCode: 200,
headers: {},
message: "You successfully signed up!",
});
If there is an error, the user will see a red box with a generic failure message. We can customize this response by adding error handling to our function. Here we are returning a custom error message and logging the error returned from the API.
try{
const signupResponse = await ripplingSDK.customObjects.records.create("class_signup__c", {"owner_role": event.current_user, "class__c": event.record_id});
console.log(JSON.stringify(signupResponse))
}
catch(error){
console.log(error);
return new FunctionResponse({
body: {},
statusCode: 400,
headers: {},
message: "Something went wrong.",
});
}
return new FunctionResponse({
body: {},
statusCode: 200,
headers: {},
message: "You successfully signed up!",
});
Put it all together and here's our completed function!
import RipplingSDK from "rippling-sdk";
import _ from "lodash";
import {
FunctionContext,
FunctionEvent,
FunctionResponse,
} from "rippling-function-types";
export async function onRipplingEvent(
event: FunctionEvent,
context: FunctionContext
) {
// Instantiate the Rippling SDK with authentication
const ripplingSDK = new RipplingSDK({ bearerToken: "sinGe..." });
try{
// Create a new Class Signup for the running user.
const signupResponse = await ripplingSDK.customObjects.records.create("class_signup__c", {"owner_role": event.current_user, "class__c": event.record_id});
// Log the successful API response
console.log(JSON.stringify(signupResponse))
}
catch(error){
// Log the error returned from the API
console.log(error);
// Return a custom error response to the user
return new FunctionResponse({
body: {},
statusCode: 400,
headers: {},
message: "Something went wrong.",
});
}
// Return a custom success response to the user
return new FunctionResponse({
body: {},
statusCode: 200,
headers: {},
message: "You successfully signed up!",
});
}
To use the function, we need to assign it to an action. We can add an action from our custom object, and select our function. Since we want to only sign the user up for the class that is selected, we choose detail view for the visibility preference.

Now, our function will be run when the user selects the Sign up action from the Class Manager app.

It went through successfully, so we can see our custom success message and a new record in class signups.

This class has a rule that limits the number of signups to three students. Since we were the third signup, we will get an error if we click sign up again.

If we click View in the error message, we can see the details of the error in the Execution log, because we logged the error in the console.

Automation
We can also trigger a function from an automation to further automate repeated tasks. For example, when someone signs up for a class, we can reduce the available seats by one.
Let's start by writing a function. We need to first instantiate an instance of the Rippling SDK using our bearer token. The token is saved in our custom settings, so we can access it using the following code:
const token = context.settings["my_api_key"]
const ripplingSDK = new RipplingSDK({ bearerToken: token });
Next, we need to grab the record_id from the event parameters. In this case, the event will be the creation of a class signup, and we will pass in the record_id of the class from the automation.
const recordId = event.parameters?.record_id;
We can then use the record_id to retrieve the custom object record for the class.
const classRecord = await ripplingSDK.customObjects.records.retrieve("class__c", recordId);
Next, let's grab the current number of available seats from the class record and create a variable to hold the updated seat count.
const currentSeats = Number(classRecord.available_seats__c);
const updatedSeats = currentSeats - 1;
Now, we need to use the Rippling SDK to update the class record with the updated seat count.
await ripplingSDK.customObjects.records.update("class__c", recordId, {
available_seats__c: updatedSeats,
});
Lastly, let's add validations, logging, and our function responses.
The completed function looks like this:
import RipplingSDK, {
FunctionContext,
FunctionEvent,
FunctionResponse,
} from "@rippling/rippling-sdk";
export async function onRipplingEvent(
event: FunctionEvent,
context: FunctionContext
) {
// Initialize an instance of the Rippling SDK
const token = context.settings["my_api_key"]
const ripplingSDK = new RipplingSDK({ bearerToken: token });
// Grab the record_id from the event parameters
const recordId = event.parameters?.record_id;
// Return an error if the record_id is not set
if (!recordId || typeof recordId !== 'string' || recordId.trim().length === 0) {
return new FunctionResponse({
statusCode: 400,
message: "Missing required parameter: record_id",
body: {},
headers: {},
});
}
try {
// Retrieve the class object record using the record_id
const classRecord = await ripplingSDK.customObjects.records.retrieve("class__c", recordId);
// Grab the current available seats and return an error if invalid
const currentSeats = Number(classRecord.available_seats__c);
if (isNaN(currentSeats) || currentSeats <= 0) {
return new FunctionResponse({
statusCode: 400,
message: "Invalid seat count in class record.",
body: {},
headers: {},
});
}
// Set the updated seat count
const updatedSeats = currentSeats - 1;
console.log(`🔄 Updating seats: ${currentSeats} → ${updatedSeats}`);
// Update the class object with the updated seat count
await ripplingSDK.customObjects.records.update("class__c", recordId, {
available_seats__c: updatedSeats,
});
console.log(`✅ Successfully updated class record ${recordId}`);
console.log(`📈 Seat count changed: ${currentSeats} → ${updatedSeats}`);
return new FunctionResponse({
statusCode: 200,
message: "Successfully updated available seats.",
body: {},
headers: {},
});
} catch (error: any) {
console.error("Failed to update class record:", error);
return new FunctionResponse({
statusCode: 500,
message: "Failed to update available seats.",
body: { error: error?.message ?? "Unknown error" },
headers: {},
});
}
}
Once we Save and Deploy the function, it will be available to call from an automation.
To do this, select Tools > Automation Studio from the sidebar, and click Create automation.
After providing a name and description, we can set our automation trigger. We want this automation to be triggered when a new class signup is created.

Next, we need to assign a variable to be passed into our function, so let's drag the Assign value to a variable step into our automation.
We need to create a variable to hold the Class ID, since that's the value our function is expecting.

Once the variable has been saved, it can be assigned to a value. Click the Insert automation variables button and select the ID from the Class custom object.

Next, we want to call our function, so let's drag the Run Function step into our automation. Select the function we just created from the dropdown and Add parameters. It's imperative that the Key matches what the function is expecting. In this case, it is record_id.

We can click the Insert workfow variables button here to assign the Class ID variable we created earlier.

📝 Note: Make sure to delete any whitespace in the parameters textboxes to avoid it being included in your parameters.

Save and Publish the automation, and verify that it is Active.

Now, when a new class signup is created from our custom app, the number of available seats for that class will be reduced by one.
