locked
Problem with import solution to CRM programmatically RRS feed

  • Question

  • Hi all,

    I have problem with import solution to CRM 2011. You can see my source code below:

    byte[] fileBytes = File.ReadAllBytes(solutionPath);
    
    ImportSolutionRequest importSolutionRequest = new ImportSolutionRequest();
    importSolutionRequest.CustomizationFile = fileBytes;
    ImportSolutionResponse importSolutionResponse = (ImportSolutionResponse)service.Execute(importSolutionRequest);
    
    PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
    service.Execute(publishRequest);
    
    FilterExpression workflowFilter = new FilterExpression();
    workflowFilter.AddCondition("name", ConditionOperator.Equal, "My workflow name");
    
    EntityCollection workflows = CRMServiceControl.RetrieveMultiple("workflow", workflowFilter, new ColumnSet(true), service);
    
    if (workflows.Entities.Count > 0)
    {
        foreach (Entity workflow in workflows.Entities)
        {
            SetStateRequest activateRequest = new SetStateRequest
            {
                EntityMoniker = new EntityReference("workflow", workflow.Id),
                State = new OptionSetValue(1),
                Status = new OptionSetValue(2)
            };
            service.Execute(activateRequest);
        }
    }

    Code with no problems imports solution to CRM 2011 but when I want to activate workflow I have found by FilterExpression so then I got this error message: Only workflow definition or draft workflow template can be published.

    Now, I do not know if that problem is in CRM solution or I made same mistake in my code.

    Thanks for help.

    Jan Holinka




    • Edited by HolinkaJan Friday, July 5, 2013 12:28 PM
    Friday, July 5, 2013 12:27 PM

Answers

  • Problem solved. I was trying to activate workflow from solution which has been overwritten by imported solution. I changed this block of code:

    if (workflows.Entities.Count > 0)
    {
        Entity workflow = workflows.Entities.FirstOrDefault();
        SetStateRequest activateRequest = new SetStateRequest
        {
            EntityMoniker = new EntityReference("workflow", workflow.Id),
            State = new OptionSetValue(1),
            Status = new OptionSetValue(2)
        };
        service.Execute(activateRequest);
    }

    I hope it is helpful for you.

    Friday, July 5, 2013 1:49 PM