Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { oracleFusionCloudErpAuth } from '../../auth';
import { makeClient } from '../../common/client';

export const updateReceivablesInvoice = createAction({
    auth: oracleFusionCloudErpAuth,
    name: 'update_receivables_invoice',
    classification: 'WRITE',
    displayName: 'Update Receivables Invoice',
    description: 'Updates an existing receivables invoice. Note: Only InvoiceStatus, PaymentTerms, and TransactionDate can be updated.',
    audience: 'both',
    aiMetadata: { description: 'Modify an existing accounts-receivable invoice identified by CustomerTransactionId; only invoice status, payment terms, and transaction date are editable. At least one field must be supplied or the call fails. Effectively idempotent since it sets fields to the values given. The invoice must already exist; use Create Receivables Invoice to add a new one.', idempotent: true },
    props: {
        customerTransactionId: Property.ShortText({
            displayName: 'Customer Transaction ID',
            description: 'The unique identifier of the receivables invoice to update.',
            required: true,
        }),
        invoiceStatus: Property.StaticDropdown({
            displayName: 'Invoice Status',
            description: 'The completion status of the invoice.',
            required: false,
            options: {
                options: [
                    { label: 'Complete', value: 'Complete' },
                    { label: 'Incomplete', value: 'Incomplete' },
                    { label: 'Frozen', value: 'Frozen' },
                ],
            },
        }),
        paymentTerms: Property.ShortText({
            displayName: 'Payment Terms',
            description: 'The payment terms assigned to the invoice.',
            required: false,
        }),
        transactionDate: Property.ShortText({
            displayName: 'Transaction Date',
            description: 'The date when the invoice was created (YYYY-MM-DD).',
            required: false,
        }),
    },
    async run(context) {
        const client = makeClient(context.auth.props);
        const { customerTransactionId, invoiceStatus, paymentTerms, transactionDate } = context.propsValue;

        const payload: Record<string, unknown> = {};

        if (invoiceStatus) payload['InvoiceStatus'] = invoiceStatus;
        if (paymentTerms) payload['PaymentTerms'] = paymentTerms;
        if (transactionDate) payload['TransactionDate'] = transactionDate;

        if (Object.keys(payload).length === 0) {
            throw new Error('At least one field (InvoiceStatus, PaymentTerms, or TransactionDate) must be provided to update.');
        }

        const response = await client.updateRecord(`/receivablesInvoices/${customerTransactionId}`, payload);
        return response;
    },
});