Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get Organizatoin Service Uri in Plugin in MS Dynamics CRM?

(0) ShareShare
ReportReport
Posted on by

Hello,

I have created a plugin which calls whenever entity modified date gets an update. I want to get Organization Service URI in it. i.e https://organizationname.crm.dynamics.com/XRMServices/2011/Organization.svc

public void Execute(IServiceProvider serviceProvider)
{
	//Extract the tracing service for use in debugging sandboxed plug-ins.
	ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

	// Obtain the execution context from the service provider.
	IPluginExecutionContext context = (IPluginExecutionContext)  serviceProvider.GetService(typeof(IPluginExecutionContext));
	// The InputParameters collection contains all the data passed in the message request.
	if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
	{
		// Obtain the target entity from the input parameters.
		Entity entity = (Entity)context.InputParameters["Target"];
		try
		{
			//// Obtain the organization service reference.
			IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
			IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
			
			//how to get organizationname.crm.dynamics.com/.../Organization.svc
		}
		catch (FaultException<OrganizationServiceFault> ex)
		{
			throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
		}
		catch (Exception ex)
		{
			throw new InvalidPluginExecutionException(String.Format("Handling custom plug-in: {0}", ex.Message), ex);
		}
	}
}

Can I get it using IPluginExecutionContext or IOrganizationServiceFactory or IOrganizationService?

Please suggest.

*This post is locked for comments

  • Suggested answer
    jm125245 Profile Picture
    on at
    RE: How to get Organizatoin Service Uri in Plugin in MS Dynamics CRM?

    You can use the "RetrieveCurrentOrganization" message. The URLs are available in the Endpoints property on Details property of the response.

            public static Uri GetOrganizationUrl(this IOrganizationService organizationService)
            {
                var request = new RetrieveCurrentOrganizationRequest();
                var organzationResponse = (RetrieveCurrentOrganizationResponse)organizationService.Execute(request);
    
                var uriString = organzationResponse.Detail.Endpoints[EndpointType.WebApplication];
                return new Uri(uriString);
            }

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How to get Organizatoin Service Uri in Plugin in MS Dynamics CRM?

    Hi Chhaya Patel,

    You can create a custom entity to store the name of the current environment with two fields.

    1. Environment Name

    2. Organization SVC Url

    In your plugin, you can fetch the organization URL field from the custom entity based on environment name.

    See: community.dynamics.com/.../168259

    Hope this helps.

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: How to get Organizatoin Service Uri in Plugin in MS Dynamics CRM?

    Hi,

    How about trying below trick? , you can get organization name from context,

    string organizationURL="https://"+context.OrganizationName+".crm.dynamics.com/XRMServices/2011/Organization.svc";

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: How to get Organizatoin Service Uri in Plugin in MS Dynamics CRM?

    Easy way to  pass the organization service URL using secure /Unsecure configuration in plugin registration tool.

    please check  below reference -

    sandeepkolarveettil.wordpress.com/.../how-to-read-unsecure-configuration

    community.dynamics.com/.../what-is-unsecure-secure-configuration-on-a-dynamics-crm-365-for-enterprise-plugin

    In addition you can also create an configuration entity with Key and Value field and keep the Organization Service URL there and using IOrganizationService retrieve the URL.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans