From 290343739e846fb8beafc3c4cb8f9a70e36c5e88 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:00:00 +0530 Subject: [PATCH 1/3] Create script.js --- .../OutboundRestDynamicEndpoint/script.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Integration/OutboundRestDynamicEndpoint/script.js diff --git a/Integration/OutboundRestDynamicEndpoint/script.js b/Integration/OutboundRestDynamicEndpoint/script.js new file mode 100644 index 0000000000..0dd7cbb606 --- /dev/null +++ b/Integration/OutboundRestDynamicEndpoint/script.js @@ -0,0 +1,54 @@ + +//Create a sample system Property called x_my_scope.api.endpoints having below object as example. make sure your company instance includes those key such as dev,prod,test or modify it with your instance name + +// { +// "dev": "https://dev-instance.example.com/api", +// "test": "https://test-instance.example.com/api", +// "prod": "https://prod-instance.example.com/api" +// } + +var EndpointConfig = Class.create(); +EndpointConfig.prototype = { + initialize: function() { + // No hardcoded object here. It will be fetched from the System Property. + }, + + getEndpoint: function() { + var propertyName = 'x_my_scope.api.endpoints'; + var endpointObjectStr = gs.getProperty(propertyName); + if (gs.nil(endpointObjectStr)) { + gs.error("EndpointConfig: System property '" + propertyName + "' not found or is empty."); + return null; + } + + try { + var endpoints = JSON.parse(endpointObjectStr); + var instanceName = gs.getProperty('instance_name'); + var environmentKey; + + if (instanceName.includes('dev')) { + environmentKey = 'dev'; + } else if (instanceName.includes('test') || instanceName.includes('uat')) { + environmentKey = 'test'; + } else if (instanceName.includes('prod')) { + environmentKey = 'prod'; + } else { + gs.error("EndpointConfig: Could not determine environment for instance '" + instanceName + "'."); + return null; + } + + if (endpoints.hasOwnProperty(environmentKey)) { + return endpoints[environmentKey]; + } else { + gs.error("EndpointConfig: Configuration not found for environment '" + environmentKey + "'."); + return null; + } + + } catch (ex) { + gs.error("EndpointConfig: Failed to parse JSON from system property '" + propertyName + "'. Exception: " + ex); + return null; + } + }, + + type: 'EndpointConfig' +}; From d335de534ff6deb90d304508a51a22813d843730 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:07:49 +0530 Subject: [PATCH 2/3] Create README.md --- .../OutboundRestDynamicEndpoint/README.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Integration/OutboundRestDynamicEndpoint/README.md diff --git a/Integration/OutboundRestDynamicEndpoint/README.md b/Integration/OutboundRestDynamicEndpoint/README.md new file mode 100644 index 0000000000..61baac05e0 --- /dev/null +++ b/Integration/OutboundRestDynamicEndpoint/README.md @@ -0,0 +1,26 @@ +This is a server-side Script Include that contains the core logic. It reads the endpoint configurations from a System Property, parses the JSON, and returns the appropriate URL based on the current instance's name. + +System Property: x_my_scope.api.endpoints +This property stores a JSON object containing the endpoint URLs for each environment. It must be created and populated in each instance that uses the utility. + +Sample JSON object: +{ + "dev": "https://dev-instance.example.com/api", + "test": "https://test-instance.example.com/api", + "prod": "https://prod-instance.example.com/api" +} + +Usage: +var endpointConfig = new EndpointConfig(); +var endpointUrl = endpointConfig.getEndpoint(); +if (endpointUrl) +{ + gs.info("Endpoint URL: " + endpointUrl); +//Use the endpointUrl in your REST call + var request = new sn_ws.RESTMessageV2(); + request.setEndpoint(endpointUrl); + // ... rest of your integration logic +} else { + gs.error("Failed to retrieve endpoint URL."); + } + From 3945e8a7c6288d72cd72dba57aef176d7e107385 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:14:21 +0530 Subject: [PATCH 3/3] Rename script.js to scriptinclude.js --- .../OutboundRestDynamicEndpoint/{script.js => scriptinclude.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Integration/OutboundRestDynamicEndpoint/{script.js => scriptinclude.js} (100%) diff --git a/Integration/OutboundRestDynamicEndpoint/script.js b/Integration/OutboundRestDynamicEndpoint/scriptinclude.js similarity index 100% rename from Integration/OutboundRestDynamicEndpoint/script.js rename to Integration/OutboundRestDynamicEndpoint/scriptinclude.js