I created a custum action in flow designer for creating record in expenses tables

Aman Mishra
Tera Contributor


Please correct the following errors before save or publish:

Action Output: Record Sys ID: Empty output value cannot be blank on publish.
Action Output: Expense Number: Empty output value cannot be blank on publish.
Action Output: Status Message: Empty output value cannot be blank on publish

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Aman Mishra 

it would be great if you add images directly in your post

It becomes difficult to go through the attachments 1 by 1

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

J Siva
Tera Sage

Hi @Aman Mishra 
It seems you missed to map your Outpu variables with the values.
Click "Exit edit mode" on your Action output and map the values to your output variables from the previous script step.

JSiva_0-1744346721414.png

Regards,
Siva

(function execute(inputs, outputs) {
    var expense = new GlideRecord('x_1027663_expenses_create_new'); // Your custom table name
    expense.initialize();

    expense.u_requested_for = inputs.requested_for;
    expense.u_short_description = inputs.short_description;
    expense.u_amount = inputs.amount;
    expense.u_approval = inputs.approval;

    var sysId = expense.insert();

    if (sysId) {
        action.setOutput('record_sys_id', sysId);
        action.setOutput('expense_number', expense.getValue('number'));
        action.setOutput('status_message', "Expense record created successfully.");
    } else {
        action.setOutput('status_message', "Expense creation failed.");
    }
})(inputs, outputs);

this is my script but when we goes to mapping then not showing that outputs
Screenshot 2025-04-12 083112.png

In your script step, you must have output variables like below. Then you need to map those output variables (from script step) to the Action output variables. PFB.

JSiva_0-1744434942681.png

 

if (sysId) {
    var expense_record = new GlideRecord('x_1027663_expenses_create_new');
    expense_record.get(sysId);
    outputs.record_sys_id = sysId;
    outputs.expense_number = expense_record.getValue('number');
    outputs.status_message = "Expense record created successfully.";
} else {
    outputs.status_message = "Expense creation failed.";
}