Calling Entity APIs from Script

Learn how to call Entity APIs from JavaScript actions.

Scripting Example to call data model APIs from JavaScript.

Example: Register a New Customer

// Example to Register a new customer// Get the customer entityvar customerEntity = context.getEntity("customer");
 
// Create the new customer objectvar newCustomer = customerEntity.createEntityObject(context);
newCustomer.firstName = input.firstName;
newCustomer.lastName = input.lastName;
newCustomer.dateOfBirth = input.dob;
newCustomer.address = input.address;
newCustomer.phone = input.phone;
newCustomer.email = input.email;
 
// Call the "insert" APIvar result = customerEntity.executeEntityAPI("insert", newCustomer);

Example: Find All Customers with Last Name "Smith"

// Example to find all customers with last name "Smith"// Get the customer entityvar customerEntity = context.getEntity("customer");
 
var customerQuery = customerEntity.createEntityObject(context);
customerQuery.lastName = "Smith";
 
// Call the "list" APIvar result = customerEntity.executeEntityAPI("list", newCustomer);

Example: Update the Address of an Existing Customer

// Example to update the address of an existing customer// Get the customer entityvar customerEntity = context.getEntity("customer");
 
// Create the customer objectvar customer = customerEntity.createEntityObject(context);
customer.id = input.customerId;
customer.address = input.newAddress;
 
// Call the "update" APIvar result = customerEntity.executeEntityAPI("update", customer);