Search This Blog

Thursday, October 4, 2012

CRM 2011: Xrm.Utility.openEntityForm

Opening a Existing or New entity record using openEntityForm

Following example shows opening a existing Quote record with required parameters

var parameters = {};
parameters["quoteid"] = quoteid;
parameters["lineitemnumber "] = "1";
parameters["quantity"] = "10";

Xrm.Utility.openEntityForm("quotedetail", null, parameters);

Hope this helps

Regards,
Vilas

Creating Custom Workflow Activity - Sample

To create a custom activity that inherits from CodeActivity

  1. Start Microsoft Visual Studio 2010.
  2. On the File menu, click New, and then click Project.
  3. In the New Project dialog box, select Workflow under Visual C# in the Installed Templates pane, and then select Activity Library.
  4. Specify a name and location for the solution, and then click OK.
  5. Navigate to the Project menu and select Properties. On the Application tab, specify .NET Framework 4 as the target framework.
  6. Add references to the Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Workflow.dll assemblies.
  7. Delete the Activity1.xaml file in the project.
  8. Add a class file (.cs) to the project. In Solution Explorer, right-click the project, select Add, and then click Class. In the Add New Item dialog box, type a name for the class, and then click Add.

Below is sample code for Cusotm workflow activity which will Accept 2 integeres as parameter and output will be total

namespace CreateEpiXml
{
    public class createEPIXML : CodeActivity
    {
        [Input("Enter First Number")]
        public InArgument<Int32> FirstNumber { get; set; }

        [Input("Enter Second Number")]
        public InArgument<Int32> SecondNumber { get; set; }

        [Output("Total")]
        public OutArgument<Int32> Total { get; set; }


        protected override void Execute(CodeActivityContext context)
        {
            int fn = FirstNumber.Get<Int32>(context);
            int sn = SecondNumber.Get<Int32>(context);
            int total;
            total = fn + sn;
            Total.Set(context, total);

        }
    }
}

Sign the workflow assembly with .snk file ( similar to plugin )

Compile the project to create an assembly (.dll).

Register your custom workflow activity using Plugin Registration tool and u can access your activity from workflow / dialogs for execution.

using that custom workflow activity from workflow or dialog , you can pass this 2 integer numbers and read the output back in workflow/dialog.

Hope this helps

Vilas