web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    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
    Nithya Gopinath Profile Picture
    17,078 on at

    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.

  • Suggested answer
    jm125245 Profile Picture
    on at

    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);
            }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans