The value returned by previously mentioned two ways can be changed by modify Dynamics CRM Web Address within Deployment Manager.
You can use the following to construct URL in FormLabrary
var serverUrl = document.location.protocol + '//' + document.location.host + '/' + Xrm.Page.context.getOrgUniqueName();
Xrm.Page.context.getServerUrl && Record URL(Dynamic) workflow dynamic values can return the base server URL which can be used either to construct web service URL (SOAP | REST) in FormLibrary or embed Record URL in a workflow.
According to SDK
The URL returned is the standard URL used to access the application. If you access the server locally using http://localhost or use an IP address rather than the actual name of the server, this will not be reflected in the value returned by this function. This means that if you are making web service calls or accessing web resources, Internet Explorer will apply security settings that apply to requests that cross domains. To avoid this, always connect to Microsoft Dynamics CRM using the standard URL.