Block a customer order in Infor M3 when a custom field is empty, with an H5 script

· Stewart Rutledge

A lot of M3 sites add custom fields to their customers for things M3 doesn't have a field for, like a shipper code or a delivery instruction. The trouble starts when an order is entered for a customer where that field was never filled in. Nobody notices at order entry, and the problem shows up days later in the warehouse or with the carrier.

An H5 script can stop that at the source: when someone creates a customer order in M3 for a customer whose custom field is empty, the script blocks it and says what's missing. This article goes through how such a script works, where the tricky parts are, and how to try it safely before anyone else sees it.

What the script needs to do

The rule is simple to say: "Block order creation for customers that are missing a value in Shipper Code." To do it, the script has to:

  1. Know which customer the order is for, from the order entry panel.
  2. Read that customer's custom field from M3.
  3. Stop the request that creates the order when the field is empty, and tell the user why.
  4. Let everything else on the panel work as before.

Finding the custom field

Custom fields are where most of the time goes when this is written by hand. A user knows the field as "Shipper Code", the name it has on the screen. The script needs to know what the field is really called in M3, which table it belongs to, what type it is, and which API reads it. Finding that out usually means a trip through the custom field setup and the API documentation before a single line is written.

In Loupe Code you skip that step. You open M3 from Loupe, go to the customer, point at the Shipper Code field, and link it to the script. Loupe Code reads your environment's metadata, so it knows the field under the name it has in your M3 and how to read it. Then you write the rule in one sentence and press Generate.

Which panel event to use

An H5 script can react to the requests a panel sends to M3, before they're sent. That's the place for a check like this: when the user presses Enter or Next on the panel that creates the order, the script gets to look first, and it can cancel the request.

Two things make this harder than it sounds.

The check needs data from M3. The event that runs before a request has to decide right away, and reading the custom field is a call to M3 that takes a moment. There are two common ways around it. The script can read the field as soon as the customer is known, so the answer is ready when the user presses Enter. Or it can cancel the request, read the field, and send the request again itself when the field has a value. Either way, the user shouldn't notice anything when everything is in order.

Block only the commands that create the order. It's tempting to write the guard the other way around: cancel every request except the few you expect. That breaks things you didn't think of, like F4 prompts, Refresh, going back with F3 or F12, and options M3 adds in a later version. Name the commands you block, typically Enter and Next on the order entry panel, and let every other request through.

Saying why the order was stopped

A blocked order without a reason is worse than no check at all, because the user will just try again and then call someone. The message should say what's missing and where to fix it, for example: "Shipper Code is missing on customer 1001. Fill it in on the customer before entering orders." Show it on the panel when the request is cancelled, and leave the user's input as it was so they don't have to type it again.

The script starts again after every response

This catches out a lot of hand written scripts. M3 runs the script again each time the panel is updated, for example after the user presses Enter and M3 answers with an error or a new panel. Anything the script remembered from before is gone, and it reads the panel fresh.

For this check that's mostly good news, because the script always looks at the customer that's on screen now. It does matter if you use the cancel, check and send again approach: the note that says "this request already passed the check" only lives until the panel updates, so set it right before you send the request again and don't rely on it afterwards. We go into more detail on this in H5 script examples for Infor M3.

Trying it before anyone else sees it

With Preview in M3 in Loupe Code, the latest build of the script runs in your own M3 session only. You attach it once to the order entry panel under Tools → Personalize → Scripts, refresh the panel, and from then on every preview runs the newest build. Nothing is deployed and nobody else is affected, so you can try a customer with the field filled in and one without, and check that F4, Refresh and the other commands still work.

When it does what you want, an administrator deploys the script and attaches it for the users or roles who enter orders.

The same pattern works for other checks

Any validation at entry follows the same shape: read what you need, block the one request that would save the wrong thing, and explain why. One we built recently stops an item from being released in a warehouse in MMS002 when its supplier has no purchase price, which otherwise shows up much later in purchasing or costing. The prompt was "Block releasing items if the supplier doesn't have a purchase price", with the fields pointed out on the panel, and the script was ready in a few minutes including the build.

If you're collecting checks like these, the article on why small M3 changes take weeks explains why they so often sit on the backlog.

Questions we get

Does the script change any data in M3?
No. It only reads the customer's field and decides whether the order request goes through. Every call it makes runs as the signed in user.

Can the check be turned off for some users?
Yes. A script is attached for a user, a role or everyone, so you can leave it off for the people who are allowed to enter orders without the field.

What happens with orders that come in through APIs or EDI?
An H5 script only runs in the H5 panels, so orders created through M3 APIs don't pass it. If those need the same rule, it belongs in M3 itself, for example as an XtendM3 extension. See XtendM3 tables and transactions without a developer.

Have a check you've wanted at order entry for a while? Send it our way and we'll show you what Loupe Code does with it. Reach out at hello@loupeapp.net, or read more about H5 scripts in Loupe Code.

This article started as a post on LinkedIn. Join the conversation there.

Got something on your M3 backlog?

Send it our way and we'll show you what Loupe Code does with it, on your own M3.

Block a customer order in Infor M3 when a custom field is empty, with an H5 script