locked
Creating a Sales Order with Detail using Workflows RRS feed

  • Question

  • I have created work flow that creates a sales order based on some details entered into a custom entity.  I would like to be able to extend that to create the order detail for the sale order so that I can complete the order entry automatically.

    Is there a ay to so this via workflow, or is the only solution to write a plug-in?

    Any help would be appreciated.

    John

    Monday, September 22, 2014 10:01 AM

All replies

  • Hi John,

    Plugin will be a better solution.

    Saad

    Monday, September 22, 2014 10:11 AM
  • Thanks Saad.

    Now that it looks like I have to write a Plug-in, is anyone able to point me in the direction of a basic set of instructions for creating records in a plug-in?  The only examples I have to hand are quite simple and rudimentary.

    Links to resources would be great.

    John

    Monday, September 22, 2014 11:15 AM
  • A workflow assembly would be a better solution. I create a similar assembly for CRM 4.0 and the code is as under. You will have to change the code for 2011/2013:-

    Here is the code. You can use it after changing invoice to salesoreder:- 
    using System.Collections.Generic;
    using System.Text;
    
    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 AutoProductDetail
    {
      [CrmWorkflowActivity("Invoice Detail Creation")]
    	public class AutoInvoiceProductDetailWF : Activity
      {
       protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
       {
         IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
         IWorkflowContext context = contextService.Context;
    
         ICrmService crmService = context.CreateCrmService();
    
    		 invoicedetail entity = new invoicedetail();
    		 
    		 entity.invoiceid = new Lookup();
    		 entity.invoiceid.Value = invoiceId.Value;
    		 
    		 entity.productid = new Lookup();
    		 entity.productid.Value = productid.Value;
    		 
    		 entity.quantity = new CrmDecimal();
    		 entity.quantity.Value = quantity.Value;
    		 
    		 entity.uomid = new Lookup();
    		 entity.uomid.Value = uomid.Value;
    		 
    		 entity.tax = new CrmMoney();
    		 entity.tax.Value = tax.Value;
    		 
    		 	 
    		 entity.isproductoverridden = new CrmBoolean();
    		 entity.isproductoverridden.Value = false;
    		 
    		 crmService.Create(entity);
    		 
         return base.Execute(executionContext);
       }
    
    		public static DependencyProperty invoiceIdProperty =
    		 DependencyProperty.Register("invoiceId",
         typeof(Lookup),
    		 typeof(AutoInvoiceProductDetailWF));
    
    		[CrmInput("Invoice")]
    		[CrmReferenceTarget("invoice")]
    		public Lookup invoiceId
    		{
    			get
    			{
    				return (Lookup)base.GetValue(invoiceIdProperty);
    			}
    			set
    			{
    				base.SetValue(invoiceIdProperty, value);
    			}
    		}
    
    		public static DependencyProperty productidProperty =
    		 DependencyProperty.Register("productid",
    		 typeof(Lookup),
    		 typeof(AutoInvoiceProductDetailWF));
    
    		[CrmInput("Product")]
    		[CrmReferenceTarget("product")]
    		public Lookup productid
    		{
    			get
    			{
    				return (Lookup)base.GetValue(productidProperty);
    			}
    			set
    			{
    				base.SetValue(productidProperty, value);
    			}
    		}
    
    		public static DependencyProperty uomidProperty =
    		 DependencyProperty.Register("uomid",
    		 typeof(Lookup),
    		 typeof(AutoInvoiceProductDetailWF));
    
    		[CrmInput("Unit")]
    		[CrmReferenceTarget("uom")]
    		public Lookup uomid
    		{
    			get
    			{
    				return (Lookup)base.GetValue(uomidProperty);
    			}
    			set
    			{
    				base.SetValue(uomidProperty, value);
    			}
    		}
    
    		public static DependencyProperty quantityProperty = 
    			DependencyProperty.Register("quantity", 
    			typeof(CrmDecimal),
    			typeof(AutoInvoiceProductDetailWF));
    
    		[CrmInput("Quantity")]
    		public CrmDecimal quantity
    		{
    			get
    			{
    				return (CrmDecimal)base.GetValue(quantityProperty);
    			}
    			set
    			{
    				base.SetValue(quantityProperty, value);
    			}
    		}
    
    
    		public static DependencyProperty taxProperty =
    			DependencyProperty.Register("tax",
    			typeof(CrmMoney),
    			typeof(AutoInvoiceProductDetailWF));
    
    		[CrmInput("Tax")]
    		public CrmMoney tax
    		{
    			get
    			{
    				return (CrmMoney)base.GetValue(taxProperty);
    			}
    			set
    			{
    				base.SetValue(taxProperty, value);
    			}
    		}
    
      }
    }
    


    Regards Faisal

    Monday, September 22, 2014 12:05 PM
  • Hi John,

    Please go through the links below:

    https://community.dynamics.com/crm/b/mscrmshop/archive/2012/03/22/step-by-step-plugin-tutorial-using-developer-s-toolkit-part-1.aspx

    http://mscrmshop.blogspot.in/2012/01/step-by-step-plugin-tutorial-using.html

    Also in SDK you can search for key word "Walkthrough a plugin" and find a basic example.

    Regards,
    Saad

    Monday, September 22, 2014 12:06 PM