locked
Workflow Organisation Name returns nothing RRS feed

  • Question

  • Trying to find the organisation name using the CrmDiscoveryService returns nothing :( However when running it within an ASP.NET application in MS CRM, it retrieves it just fine but not when executed within a workflow assembly in MS CRM 4.0

    any ideas? How can I obtain an organisation name regardless of which user account (workflow) is being used?
    Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Friday, February 20, 2009 1:07 PM

Answers

  • You can get organizationid from IWorkflowContext.OrganizationId within the workflow activity. The OrganizationId property corresponds to the organization.organizationid property, which is the primary key for the organization entity. Use TargetRetrieveOrganization with OrganizationId to retrieve the record and access name Property to get the name of the orgnanization.
    Ronald
    • Marked as answer by ahmedilyas Friday, February 20, 2009 4:37 PM
    Friday, February 20, 2009 4:27 PM

All replies

  • You can get organizationid from IWorkflowContext.OrganizationId within the workflow activity. The OrganizationId property corresponds to the organization.organizationid property, which is the primary key for the organization entity. Use TargetRetrieveOrganization with OrganizationId to retrieve the record and access name Property to get the name of the orgnanization.
    Ronald
    • Marked as answer by ahmedilyas Friday, February 20, 2009 4:37 PM
    Friday, February 20, 2009 4:27 PM
  • Thanks, but whilst you maybe correct, I cannot see this working as you still need to pass an authentication token into the CrmService, which needs the Organization name.....


    Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Monday, February 23, 2009 1:21 PM
  • Why do you need to pass organization name into CrmService in the first place when an instance of CrmService is ready for use from context? Are you adding web reference in workflow activity? The same principle applies to plugins as well.


    using System;  
    using System.Collections;  
    using System.Workflow.ComponentModel.Compiler;  
    using System.Workflow.ComponentModel.Serialization;  
    using System.Workflow.ComponentModel;  
    using System.Workflow.ComponentModel.Design;  
    using System.Workflow.Runtime;  
    using System.Workflow.Activities;  
    using System.Workflow.Activities.Rules;  
    using System.Reflection;  
     
    using Microsoft.Crm.Workflow;  
    using Microsoft.Crm.Sdk;  
    using Microsoft.Crm.SdkTypeProxy;  
    using Microsoft.Crm.Sdk.Query;  
     
    namespace SampleWorkflows  
    {  
       [CrmWorkflowActivity("A sample custom activity")]  
       public class QACustomActivity : Activity  
       {  
          protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)  
          {  
     
             IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));  
             IWorkflowContext context = contextService.Context;  
     
             ICrmService crmService = context.CreateCrmService();  
               
             task entity = new task();  
             entity.subject = taskId.Value.ToString();  
             entity.activityid = new Key(taskId.Value);  
             crmService.Create(entity);  
     
             return base.Execute(executionContext);  
          }  
     
          public static DependencyProperty taskIdProperty =  
             DependencyProperty.Register("taskId",  
             typeof(Lookup),  
             typeof(QACustomActivity));  
     
          [CrmInput("The id")]  
          [CrmOutput("The output")]  
          [CrmReferenceTarget("task")]  
          public Lookup taskId  
          {  
             get 
             {  
                return (Lookup)base.GetValue(taskIdProperty);  
             }  
             set 
             {  
                base.SetValue(taskIdProperty, value);  
             }  
     
          }  
     
     
       }  
    }  
     

    Ronald
    Monday, February 23, 2009 2:53 PM
  • Thanks for that, that is true. The reason was because I have made this "common" assembly (like a framework) where it sits on its own and has references to the webservices and nothing else (does not derrive from the workflow activity).... this is why as I wanted it to be more of a logic and DAL thing where my other workflow plugins can call and use this common assembly (does that make sense?)



    The thing with your approach I am guessing, would be, how can I then use your method to get the organization name using the Target class? The Target class exists when you add the CRM SDK web service references.....
    Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Monday, February 23, 2009 3:07 PM
  • Get the name using Target class within workflow activity first then pass it to the "common" assembly.
    Ronald
    Monday, February 23, 2009 3:33 PM