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/6] 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/6] 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/6] 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 From 3dd09c0cb15130e9e35aa0ca7df6ee3f39b5543c Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:18:21 +0530 Subject: [PATCH 4/6] Delete Integration/OutboundRestDynamicEndpoint directory --- .../OutboundRestDynamicEndpoint/README.md | 26 --------- .../scriptinclude.js | 54 ------------------- 2 files changed, 80 deletions(-) delete mode 100644 Integration/OutboundRestDynamicEndpoint/README.md delete mode 100644 Integration/OutboundRestDynamicEndpoint/scriptinclude.js diff --git a/Integration/OutboundRestDynamicEndpoint/README.md b/Integration/OutboundRestDynamicEndpoint/README.md deleted file mode 100644 index 61baac05e0..0000000000 --- a/Integration/OutboundRestDynamicEndpoint/README.md +++ /dev/null @@ -1,26 +0,0 @@ -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."); - } - diff --git a/Integration/OutboundRestDynamicEndpoint/scriptinclude.js b/Integration/OutboundRestDynamicEndpoint/scriptinclude.js deleted file mode 100644 index 0dd7cbb606..0000000000 --- a/Integration/OutboundRestDynamicEndpoint/scriptinclude.js +++ /dev/null @@ -1,54 +0,0 @@ - -//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 6a63cda3bb5eb86fae821ca7d00842f3903cdfeb Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:20:57 +0530 Subject: [PATCH 5/6] Create scriptinclude.js This utility function used to get dynamic endpoints configured in system property based on current instance URL. --- .../DynamicOutboundEnpoints/scriptinclude.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Integration/RESTMessageV2/DynamicOutboundEnpoints/scriptinclude.js diff --git a/Integration/RESTMessageV2/DynamicOutboundEnpoints/scriptinclude.js b/Integration/RESTMessageV2/DynamicOutboundEnpoints/scriptinclude.js new file mode 100644 index 0000000000..0dd7cbb606 --- /dev/null +++ b/Integration/RESTMessageV2/DynamicOutboundEnpoints/scriptinclude.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 9cbea2f66a8c7d2377167b46654eaa51c9363fae Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:23:03 +0530 Subject: [PATCH 6/6] Create README.md dynamic outbound endpoints --- .../DynamicOutboundEnpoints/README.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Integration/RESTMessageV2/DynamicOutboundEnpoints/README.md diff --git a/Integration/RESTMessageV2/DynamicOutboundEnpoints/README.md b/Integration/RESTMessageV2/DynamicOutboundEnpoints/README.md new file mode 100644 index 0000000000..9f9723f418 --- /dev/null +++ b/Integration/RESTMessageV2/DynamicOutboundEnpoints/README.md @@ -0,0 +1,27 @@ +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."); +} +