Netsuite - Dynamically determine domain url - portlet

I have been researching for quite a while now about how to dynamically determine the domain url of a netsuite account.
In general I have seen developers hardcoding domain url to "https://system.na1.netsuite.com" or "https://system.netsuite.com" in portlets.
But nobody determines it dynamically.
This in general is a bad practice(although I know Netsuite redirects) and I presume there should be way to determine the correct URL.
Can anyone help in this?

Depending on what you're trying to find the URL for, you can use nlapiResolveURL to dynamically generate the URL for several different NetSuite objects (Suitelets, records, etc). I suggest investigating that function to see if it fits your needs.

Another options is to check the current environment.
You can use nlobjContext to get the environment. Below is the code snippet
var url = 'sandboxurl';
if(nlapiGetContext().getEnvironment()=='PRODUCTION'){
url = 'productionurl';
}
Hope it helps

Depending on your needs, you may simply be better using relative urls. If you use window.location, anything that starts with a / is a relative location: How do I set window.location to a specific path (without a host)? has a good example.
If there is a specific example of what you are using the url for, we might be able to help more!

Related

Raw urls on GitHub keep changing

I need a Markdown file to be able to refer to diagrams in my repository and for the links to remain valid as the diagrams are updated. I am finding that the url I get when I right-click the Raw button and copy the link varies between these two forms:
https://github.com/user/repo/raw/branch/folder/file.png
https://raw.github.com/user/repo/branch/folder/file.png
Note the change in the position of "raw".
Could anyone explain, please, what is happening?
One of these URLs is a redirect to the other, or they're both in a redirect chain to a third link. It's possible your browser has prefetched one and knows the destination already in some cases, and not in others.
I'd take either one to a command-line prompt and give it to curl -Lv and see where the final one ends up. Alternately, you can use the API to query for the raw link for this object, and whatever it gives you should be correct.
I will tell you that the latter domain name is probably not correct; I would suspect that the right URL is at the domain raw.githubusercontent.com, but I'd ask the API to be sure.

AEM/Sling: How do I implement dynamic sling selector?

TLDR: I want setup an AEM page that accepts firstname and lastname as parameter using an SEO friendly URL.
Going to www.host.com/mycontent.richard.williams.html will display information relevant to Richard Williams.
If I go to www.host.com/mycontent.john.smith.html, the page will display information relevant to John Smith.
SEO friendly example: www.host.com/mycontent.richard.williams.html
not SEO friendly example: www.host.com/mycontent.html?firstname=richard&lastname=williams
So I've been following this guide (not sure if this is the best example/guide to help me): http://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/
And while it works well for my the example
#SlingServlet(resourceTypes="geometrixx/components/hompepage", selectors={"firstname","lastname"}, extensions="html",methods="GET", metatype=true)
I am trying to make it dynamic.
At the moment, I can only access the servlet if access via: http://localhost:4502/content/geometrixx/en.firstname.lastname.html
I want to make firstname and lastname dynamic parameters/selectors. Like if for example I want to pass the values "richard.williams", I can then use: http://localhost:4502/content/geometrixx/en.richard.williams.html
if I try to use http://localhost:4502/content/geometrixx/en.richard.williams.html right now, I get a blank page.
So basically I want to use selectors for passing parameter values to my page.
Any ideas how this can be done?
ps. At the moment, I only testing/experimenting in my local instance of AEM.
Selectors in sling don't provide the functionality of placing variables in the URL path. i.e. you cannot add {pathParam} like in Spring to sling servlet URL.
In general, selectors are not recommended to be used like an input to a function. They are to be used more like file extensions.
For eg. A request to /mycontent.html returns the same resource as /mycontent.mobile.html. The only difference being, the latter requests for a mobile friendly version.
Request params on the other hand serve the purpose of providing inputs to the servlet.
I cannot think of any direct way to attach a servlet to dynamic paths in sling. You can try using suffix, they are cacheable in the dispatcher, but I can't comment on the SEO friendliness of using suffix.
Consider this URI - /mycontent/user.json/john/smith
Register a servlet using the path /mycontent/user and you can use
String[] names = request.getRequestPathInfo().getSuffix().split(suffix, '/')
to retrieve the suffix contents.
Take a look at answers in this question. Sling ResourceProvider and integrating with jax-rs are other ways you can accomplish this.
Technically this would be feasible with the use of OptingServlet (see https://sling.apache.org/documentation/the-sling-engine/servlets.html#optingservlet-interface)
Your accepts method could easily recognise the expected resourceType and react appropriately.
As mentioned in the docs this approach is discouraged and the solution proposed by Subhash to use suffixes seems way more elegant.
You can create a components which reads selector from the request and add that compoent to en.html

Google Content Experiments for whole part of the site

I want to run an A/B-test or an experiment for whole part of the site. For example on my /blog/ page, where one variation would have a newsletter form and other variation a free ebook download button.
The problem is that I have to use a full URL path for the experiments, for example /blog/2013/article/1?var=1 and /blog/2013/article/1?var=2 With this method I would need create a new experiment for each blog post. This is impossible.
Any tips on how to approach this?
It's possible, but the documentation is lacking.
When you choose your variation URLs, you need to use relative instead of http://. This let's you use query parameters to define the variations, instead of the full URL. In your example, you would define your original page as:
http: //www.example.com/blog/2013/article/1
and your variation URLs would be ?var=1, var=2, etc. using relative as the option in the dropdown (instead of http:// or https://).
Here's the not-so-clear documentation on using relative URLs for your variations:
https://support.google.com/analytics/answer/2664470?hl=en&ref_topic=1745208
One important thing to remember is that if you're doing it this way, you need to include the content experiment code on every "original" page.
There's also another way to have even more control over serving the variation pages and controlling the experiment using the Content Experiments JavScript API. This is a relatively new feature - you can see the developer documentation about this here:
https://developers.google.com/analytics/devguides/collection/gajs/experiments
I am not sure this is possible. You might look at a more robust yet simple to use tool like Visual Website Optimizer or Optimizely.

Panoramio api for searching by tag

I am in developing web application to allow user search Panoramio images using a tag. Would be appreciate if someone has done previously and share how you do that to me.
You'll find all the information you need to know here:
https://developers.google.com/maps/documentation/javascript/examples/layer-panoramio-tags
Its easy to implement, give it a go. As long as you've set up the Panoramio service correctly, it should only take a line or two of code.

Duplicate URLs in Zend

I am developing a ZF website: howtowritecitations (dot) com
and it has a TOS page:
howtowritecitations (dot) com/termsofservice
But what are these duplicate pages?
http://www.howtowritecitations.com/termsofservice/index
http://www.howtowritecitations.com/index.php/termsofservice
http://www.howtowritecitations.com/index.php/index/termsofservice
Where did they come from? Will this be a problem? I hope not. For example, when Google crawls the page, it will only find and index howtowritecitations (dot) com/termsofservice, right?
If it is a potential problem, show me in the right direction so I can try and solve it.
Someone suggested to start looking at getRequestUri() in routeShutdown() (or something similar)
to use preg_replace to remove index.php, in order to 301-redirect to the proper URL, but I lost here.
Thanks in advance for advice or comments
This is caused by the routes you have setup. By default, Zend Framework applications usually route like:
www.yoursite.com/:controller/:action/:param
Right now, your termsofservice controller located at www.yoursite.com/termsofservice when called will show the :index action by default when no action is specified without changing the URL. It is also perfectly valid to access it using www.yoursite.com/termsofservice/index.
In order to fix these, you need to setup custom routes where everything that matches www.yoursite.com/:controller/* will route to www.yoursite.com/:controller. That way Google will never get a chance to see an alternate URL to index.