How to Block a NetSuite Purchase Order Save with a Workflow Error Message

Use a SuiteFlow Return User Error action on Before Record Submit to stop a purchase order from saving without a Department, and tell the user what to fix.

The quick answer

Create a workflow on Transaction records with the Purchase Order sub type that runs On Create and On View Or Update. On its start state, add a Return User Error action, set Trigger On to Before Record Submit, and give it the condition Department Is Empty. Put the message the user should see in Text, for example "Select a Department before you save this purchase order." When someone saves a purchase order with Department blank, NetSuite doesn't save it. It shows your message on a Notice (SuiteScript) page with a Go Back button. Once Department is filled in, the condition is false and the save goes through.

The screenshots show sample data. The company, user, vendor and purchase orders are fictional. Use your own records and values when following the steps.

Before you start

You need the Administrator role, or a role that can create workflows and edit purchase orders. SuiteFlow has to be enabled, the Departments feature has to be on, and Department has to be visible on the purchase order form your users save.

In this example, Copperline Pump & Valve reports spending by department, but purchase orders keep getting saved without one. Renata Okafor, the administrator, builds the rule herself. She leaves the workflow in Testing while she builds it, so it only runs for her as its owner and nobody else gets blocked by a half-finished rule.

01. Find a purchase order saved without a Department

Go to Transactions > Purchases > Enter Purchase Orders > List. Three orders for Tidewater Bearing Co. are listed: PO2289, PO2290 and PO2291.

PO2291, Pump rebuild parts, is the 2,696.40 order.

Click PO2291. It totals 2,696.40, and its Classification section has Subsidiary Copperline US and Location Riverside Plant, but Department is blank. Nothing stopped anyone from saving it that way.

PO2291 was saved with Department blank.

02. Create the workflow

Go to Customization > Workflow > Workflows > New. Enter the Name PO Department Required. Type Transaction in Record Type and press Tab, then select Purchase Order in Sub Types. Leave Release Status at Testing and Initiation at Event Based. Execute as Admin stays unchecked here; turn it on only if the condition has to read values the saving user's role can't see.

Name, Record Type Transaction, the Purchase Order sub type, and Release Status Testing.

Under Event Definition, check On Create and On View Or Update. On Create covers new purchase orders. On View Or Update starts the workflow when an existing order, like PO2291, is opened or edited. Opening an order doesn't trigger the error, though. The action you add next only runs when someone saves. Click Save.

On Create and On View Or Update are both checked.

The workflow designer opens with one state, State 1, marked START. The Workflow panel shows Record Type Transaction (Purchase Order), Release Status Testing and Events On Create, On View Or Update.

The new workflow has one state and runs in Testing.

03. Add the Return User Error action

Double-click State 1 to open the Workflow State window. On its Actions subtab, click New Action and choose Return User Error. The Workflow Action form opens.

In the Parameters section, type the message in Text: Select a Department before you save this purchase order. This is exactly what the user will see, so say which field to fix.

Text is the message the user sees when the save is blocked.

Scroll back up and check Trigger On. It should be Before Record Submit, which runs after the user submits the form and before NetSuite writes the record. That's the point where a save can still be stopped. Don't assume the default; check the value.

Trigger On is Before Record Submit. The Condition is still empty.

Without a condition, the action blocks every save. The condition goes on this action, not on the workflow. Click the open icon next to Condition. In the Workflow Condition window, type Department in Field and press Tab, choose empty as the Compare Type and leave Value blank. Click Add, then Save. Some accounts list the header field as Department (Main). Pick the body field, not a line-level Department.

Field Department, Compare Type empty.

Back on the action, the Condition box reads Department Is Empty. The error only fires while Department is blank. Click Save on the action.

The action now has the condition Department Is Empty.

State 1's Actions list now has one row: Return User Error with the message, Trigger On Before Record Submit, and Condition Department Is Empty. Click Save on the state.

One Return User Error action on State 1.

With State 1 selected, the State panel lists Return User Error under Record Save, Before Record Submit. You can also add the action from here: select the state and click New Action at the bottom of the panel.

The State panel groups the action under Record Save, Before Record Submit.

04. Try to save without a Department

Go back to Transactions > Purchases > Enter Purchase Orders > List and click Edit next to PO2291. Department is still blank. Don't change anything.

PO2291 open for editing, Department still empty.

Click Save. NetSuite doesn't save the order. A Notice (SuiteScript) page shows the workflow's message and a Go Back button.

The save is rejected with the action's Text.

No script is involved. NetSuite uses the same error page it shows for other server-side save errors, so the title says SuiteScript anyway.

05. Fix the field and save

Click Go Back to return to the PO2291 edit form. Expect anything you entered since the last save to be cleared, so re-enter it along with the fix. In Classification, choose Maintenance in Department.

Department is now Maintenance.

Click Save. Department isn't empty anymore, so the condition is false and the action doesn't fire.

PO2291 saved, with Department Maintenance.

Check the result (example values)

  1. Saving PO2291 with Department blank opened a Notice (SuiteScript) page with "Select a Department before you save this purchase order." and nothing was saved.
  2. After choosing Maintenance, the save went through with the confirmation Transaction successfully Saved.
  3. PO2291 shows Department Maintenance and the same 2,696.40 total.

The workflow is still in Testing, so right now it only blocks its owner. Other roles won't hit it until you set Release Status to Released, so release it in a sandbox first if you can and test a save with each role that creates purchase orders. Test an order that already has a Department too, to make sure it still saves.

Purchase orders also arrive through CSV imports, integrations, scripts and requisition approvals. Whether the action runs for those depends on its Event Types and Contexts, and the error isn't much use to an import or an integration that has no person reading it. Test each channel you rely on before you treat this workflow as the only control on Department.

Common questions

Why use a workflow instead of making Department mandatory on the form?

A mandatory field on a form only applies to that form. A workflow applies to every purchase order the workflow runs on, whichever form someone uses, and it can be conditional, for example only for one subsidiary or one vendor. It also lets you write the message, so the user knows exactly what to fix.

Should Return User Error use Before Record Submit or Before User Submit?

Before Record Submit runs after the user clicks Save and before NetSuite writes the purchase order, so it can stop the save. That's the trigger used here, and the rejected save shows the error page with Go Back. Before User Submit runs in the browser before the form is submitted. It can show the message earlier on the form, but it only covers saves made in the browser, so use Before Record Submit when the rule has to hold on the server.

Why does the error page say Notice (SuiteScript) when there's no script?

NetSuite shows server-side save errors on that page, and a Return User Error action on Before Record Submit is one of them. The title doesn't mean a custom script ran. What matters is that the purchase order wasn't saved.

Why don't other users get the error?

The workflow is in Testing, and a workflow in Testing only runs for its owner. Set Release Status to Released when you're ready, then check that the roles that create purchase orders hit the error and can save once Department is filled in.

Does this also block CSV imports and integrations?

It can, if the action runs for that context and event. Check the action's Event Types and Contexts. An import or integration has no one to read a Go Back page, so the save fails and the message comes back as the error. Test each channel you rely on, and use a script or another control if the rule has to cover a path the workflow doesn't.

How do I block more than one problem, or only for some subsidiaries or vendors?

Add more conditions to the Return User Error action and join them with And or Or. Department Is Empty plus a Subsidiary or Vendor condition limits the block to those records. If different problems need different messages, add a separate Return User Error action for each one.