public static string GenerateUrlForApp(IOrganizationService service, string recordUrl, string appName)
        {
            // Get base URL of the instance.
            string baseUrl = recordUrl.Split('?')[0];

            // Get the entity reference from the Dynamic Record URL passed to the CodeActivity.
            DynamicUrlParser dynamicUrlParser = new DynamicUrlParser(recordUrl);
            EntityReference  entityReference  = dynamicUrlParser.GetEntityReference(service);

            // Query for AppModule record.
            AppModule appModule = GetAppModule(service, appName);

            // Create URL.
            return(CreateRecordUrl(baseUrl, appModule, entityReference, dynamicUrlParser));
        }
        public static string CreateRecordUrl(string baseUrl, AppModule appModule, EntityReference entityReference, DynamicUrlParser dynamicUrlParser)
        {
            // Compose the URL with the query string parameters needed to access the Unified Interface apps.
            string queryString = string.Empty;

            if (appModule.ClientType == AppModule.ClientTypes.UNIFIED_INTERFACE)
            {
                queryString = string.Join("&", new string[] {
                    "appid=" + appModule.Id.ToString("D"),
                    "pagetype=entityrecord",
                    "etn=" + entityReference.LogicalName,
                    "id=" + entityReference.Id.ToString("D")
                });
            }
            else if (appModule.ClientType == AppModule.ClientTypes.CLASSIC_INTERFACE)
            {
                queryString = string.Join("&", new string[] {
                    "appid=" + appModule.Id.ToString("D"),
                    "etc=" + dynamicUrlParser.EntityTypeCode,
                    "id=" + entityReference.Id.ToString("D"),
                    "newWindow=true",
                    "pagetype=entityrecord"
                });
            }

            return(baseUrl + "?" + queryString);
        }