Answering my own question: I was able to get the code sample to work by including an exports directive/keyword to the utility.js file.
utility.js
-------------------------------------------------
exports.getSomeValue = function ()
{
return 'some value';
}
But also have a follow-up question: In the DataPower documents for GatewayScript programming
Gateway programming model and GatewayScript - IBM Documentation it states that ECMAScript and CommonJS are supported specifications. Is there a preferred method for creating reusable GatewayScript modules? ECMAScript or CommonJS?
My code example was CommonJS.
------------------------------
Steve Ruscik
------------------------------
Original Message:
Sent: Tue June 21, 2022 09:27 AM
From: Steve Ruscik
Subject: GatewayScript common/shared utility libraries on IBM API Connect v10
Trying to see if this is possible.
When using the GatewayScript policy can the script reference external GatewayScript libraries to call standard utility functions? Since I need to write GatewayScript policies it would be useful to reference standard functions that are reused across API definitions and not embedded into each API specification file.
Example:
GatewayScript Policy:
var apim = require('apim');
var utils = require('local://common_utility.js');
apim.setvariable('message.headers.SOME-HEADER', utils.getSomeValue());
I have tried a couple of times to get this to work, but have been getting 500 errors.
result: "500 Internal Server Error"
error-code: "0x00c30044"
error-subcode: "0x00c30044"
------------------------------
Steve Ruscik
------------------------------