Skip to main content

Create a Custom Service with AI

This article walks through creating a Purchase Request Amount Calculator that calculates totals from purchase request line items.

Use Start with AI to describe reusable business logic in plain language and let AI help create a Custom Service.

AI first prepares an Implementation Plan for your review. You can check the proposed inputs, outputs, and processing rules, request changes, and approve the plan before creation begins.

This article walks through creating a Purchase Request Amount Calculator that calculates totals from purchase request line items.

Before you begin

Prepare the following information:

  • Purpose: What the service should do.

  • Inputs: The values supplied when the service is called.

  • Processing rules: How to calculate, validate, or transform those values.

  • Outputs: The results the service should return.

  • Dependencies: Any application resources or external connections it needs.

The example in this article processes supplied line items only. It does not read or modify application records.

Describe your service

Open your application and click + in the top navigation to open New application resource.

In the Create with AI section:

  1. Select Custom services. Click Show more if it is not visible.

  2. Enter your requirements.

  3. Click Start with AI.

Include specific rules and expected results so AI can propose a configuration that matches your business requirements.

Answer clarification questions

AI may ask questions before preparing the plan. For example:

  • Is the tax rate entered as a percentage or a decimal?

  • Can the line item collection be empty?

  • Should one invalid item stop the entire calculation?

  • Should amounts be rounded per line or after calculating the total?

  • Which fields should appear in the returned results?

Review the Implementation Plan

AI generates an Implementation Plan after reviewing your requirements. Open it and check the proposed configuration.

For this example, review the following:

Item

Expected configuration

Service name

Purchase Request Amount Calculator

Line item inputs

Description, Quantity, and Unit Price

Tax Rate

Optional percentage; defaults to 0

Line amount

Quantity × Unit Price, rounded to two decimal places

Subtotal

Sum of the rounded line amounts

Tax Amount

Subtotal × Tax Rate ÷ 100, rounded to two decimal places

Total Amount

Subtotal + Tax Amount, rounded to two decimal places

Validation

At least one item; Quantity and Unit Price must be non-negative numeric values

Error handling

Return validation errors without calculated totals if any item is invalid

Execution scope

Process supplied data only; no application record access or external calls

Also review the proposed variable names and types. Make sure they will be easy to map when calling the service from a workflow, form action, or AI tool.

To request a change, reply in the conversation. For example:

Rename the total output to TotalAmount and include the item index in each validation error.

Review the updated plan before proceeding.

Approve the plan and create the service

When the plan matches your requirements, confirm in the conversation. For example:

Approve the plan and create the Custom Service.

AI then creates the service according to the approved plan.

Review the creation result and use the provided link to open the service.

Approving the plan authorizes creation. You should still review and test the generated logic before using it in a business process.

Review the generated configuration and code

Open the service and check that its variables and implementation match the approved plan.

Pay particular attention to:

  • Input and output names and types.

  • Default values.

  • Validation for missing, non-numeric, and negative values.

  • Calculation and rounding order.

  • Returned results and error messages.

The Custom Service code editor allows you to review, edit, and test the service logic.

Test the service

Start with sample data that is easy to verify manually.

For example, supply these line items and set Tax Rate to 9:

Description

Quantity

Unit Price

Expected line amount

Office chairs

2

150.00

300.00

Monitor stands

3

40.00

120.00

The expected results are:

Output

Expected value

Subtotal

420.00

Tax Amount

37.80

Total Amount

457.80

Then test validation and boundary cases:

Test case

Expected behavior for this example

Tax Rate is omitted

Calculate using 0%

No line items are supplied

Return an error requiring at least one item

Quantity is missing

Return a validation error identifying the item

Unit Price is non-numeric

Return a validation error identifying the item

Quantity or Unit Price is negative

Return a validation error

Values contain additional decimal places

Apply the rounding rules defined in the plan

If a result is incorrect, describe the input, actual result, and expected result to AI. Review the changes and test again.

Publish and use the service

Check the service’s current publication status. If the version is still a draft, finish testing before publishing it.

Save keeps your changes as a draft. Only published Custom Services can be selected and invoked by workflows, form actions, or AI tools.

For this example, a calling workflow or form action can pass purchase request line items to the service and use the returned amounts in subsequent steps.

The calculator itself only performs calculations. To save its results to a purchase request record, configure the required update operation in the calling process.

Continue making changes with Ask AI

After creation, use Ask AI to return to the saved conversation and request further changes.

For example:

Add an optional Discount Amount input. Subtract it from Subtotal before calculating tax. Reject discounts that are negative or greater than Subtotal. Update the implementation plan before making changes.

Confirm the revised calculation order and validation rules. After the changes are applied, review the implementation and rerun the relevant tests.

Did this answer your question?