Hi,
I tried to check the runmode in AEM in order to add the script accordingly to PROD and non-PROD environments. When I try to execute the code both the script is displaying in the PROD and non-PROD environment. Below is the code added:
Runmode.Java :
import com.adobe.acs.commons.util.ModeUtil;
public boolean isProduction() {
return ModeUtil.isRunmode("prd");
}
component.html :
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @nivethaS
You can't check the runmodes in AEMaaCS as you used to do before using SlingSettingsService.
Please check alternatives at:
https://www.theaemmaven.com/post/the-slingsettingsservice-run-modes-in-aemaacs
https://blog.developer.adobe.com/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b
Example :
Hi @nivethaS
Please try to check your code with below piece of code. The run mode you are passing in function isProduction should contain correct information, try to debug you java code and see what info. you are getting.
public static WCMMode getMode(SlingHttpServletRequest req) {
if (req.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME) == null) {
return WCMMode.DISABLED;
} else {
String mode = String.valueOf(req.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME));
try {
return WCMMode.valueOf(mode);
} catch (IllegalArgumentException ex) {
return WCMMode.DISABLED;
}
}
}
public static boolean isRunmode(String mode) {
return runmodes.contains(mode);
}
Thanks
Tarun
Hi @TarunKumar
I need to check whether the environment is prod or non prod but the codded you shared is to validate the wcmmode right?
Hi Nivetha,
You are checking for a specific run mode called 'prd' in code supplied,
Kindly ensure that your instance actually contains or does no contain this specific run mode.
Follow following link to read about setting specific run modes:
Regards,
Peter
Hi @nivethaS
You can't check the runmodes in AEMaaCS as you used to do before using SlingSettingsService.
Please check alternatives at:
https://www.theaemmaven.com/post/the-slingsettingsservice-run-modes-in-aemaacs
https://blog.developer.adobe.com/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b
Example :
@nivethaS Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Hi @nivethaS
In AEM Cloud, runmode detection using com.adobe.acs.commons.util.ModeUtil isn't supported. AEM Cloud utilizes environment variables instead of traditional runmodes like "prod" or "stage".
Therefore, you need to adapt your code to use these environment variables:
1. In Runmode.Java:
Replace your existing logic with:
public boolean isProduction() { return System.getenv("ENVIRONMENT_TYPE").equals("production"); }
This retrieves the ENVIRONMENT_TYPE environment variable and checks if it's equal to "production".
2. In component.html:
Update your data-sly-test syntax and use the environment variable directly:
<sly data-sly-test="${System.getenv('ENVIRONMENT_TYPE') eq 'production'}"> </sly> <sly data-sly-test="${System.getenv('ENVIRONMENT_TYPE') ne 'production'}"> </sly>
This checks the ENVIRONMENT_TYPE value against "production" using the equality and inequality operators (eq and ne).
By changing your approach to leveraging environment variables, you'll achieve proper runmode-based script loading in AEM Cloud.
Remember to clear the AEM Cloud dispatcher and browser cache after making these changes to ensure you're seeing the updated behavior.
@nivethaS Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies