Saturday, June 30, 2012

CRM2011 Workflow

In this blog I would share some of the OOB features of CRM2011 workflows that we don’t use very frequently. Here are some of those features
  • Workflow Templates
  • Automatically deleting the completed workflow jobs
  • Use of “Activity Count” and “Activity Count Including Process”

Workflow Templates

When we create a workflow , we have an option to activate the workflow as templates.
image
We can also activate an existing workflow as a ”Process Template” as long the workflow is in draft/deactivate state.
One of the biggest benefit of saving/activating a workflow as template is that we can create a copies of existing workflow without creating a workflow from scratch.

Automatically deleting the completed workflow jobs

In CRM, when the workflow is completed, it still appears in the system jobs as shown in the following screen.
image
We can delete these succeeded workflow entries automatically by checking the “Automatically delete completed workflow jobs(to save disk space” on the Administration tab of the workflows as shown in the following screen shot.
image

Use of “Activity Count” and “Activity Count Including Process”

When we use wait condition or check condition in workflows, under the “Local Values” there is a “Process” option  and there are 4 sub options available for “Process” as shown the screen shot. The 4 options are :
  • Execution Time
  • Activity Count
  • Activity Count Including Process
  • Timeout
image4

Execution Time

It will give you the execution time (date and time) of the workflow.

Activity Count

It will return the total number of activities excluding activities created through workflow steps associated to the workflow entity.

Activity Count Including Process

It will return the total number of activities including activities created through workflow steps associated to the workflow entity.

Timeout

It will pause the workflow execution for specified data and time. Look at the following blog for detail explaination
http://www.dynamicscrmtrickbag.com/2009/07/12/waits-timeouts/

Monday, June 25, 2012

Importing notes attachments in CRM2011

Recently I came across a situation, where I have to move an entity records and file attachments from one deployment to another.I have done this in CRM 4.0 using data migration wizard. I was thinking if I can do the same using “Data Import” tool in CRM2011.
After some searching on Google, I found few dynamic forums and a LinkedIn group that were very helpful. Here is a link to the LinkedIn group. Here is scenario. I have 2 separate deployments of CRM2011. They are not connected to each other. I need to move the accounts and file attachments (notes) from one deployment to another.
The solution is consists of 2 parts
  1. On CRM deployment 1, I will write some custom code to create a zip file that will contain 2 CSV file and “Attachments” folder containing all the attachments.
  2. On CRM deployment 2. I will use built-in “Data Import” tool to import this zip file into the system.

Creation of Zip files

In this blog, I won’t be writing any custom code to create a zip file but will explain the structure of zip file.I have created a folder named “Import”. In “Import” folder, I have created 2 files and folder as shown in the screen shot.
image
The account.csv file will look like the following screen
image
The  note.csv will like the following screen.
image
The fieldnames “File Name”, “PhysicalFileName” and “Regarding” are very important here. They are important to import the attachments and linking to the proper account records.
  • Column “Filename” will be mapped to “FileName” field on the notes entity.
  • Column “PhysicalFileName” be mapped to the “Document” field on the notes entity.
  • Column “Regarding” will be mapped to the “Regarding” field in the notes entity.
Attachments folder will contain all the attachments files. Just make sure that the "PhysicalFileName” of the files are unique. If I am creating this zip file through code then I may add the account number as prefix to the files.
Now the next step will be to zip this “Import” folder into “Import.zip” file.

Importing the zip file

Now take this “Import.zip” file to the second deployment and import the file using “Data Import” tool. Here are the steps:
image
image
image
image
If the names of CSV files match the crm entities, “Data Import” wizard will map them to the appropriate CRM entities as shown the screen shot above.
image
Now here you can click on the entities and map the fields between your CSV files and CRM entities. I am going to map the notes entity fields in the next step

image
Make sure these fields are mapped as shown in the above screen shot.

image
image
If you are going to use this process on regular basis, save the data map by providing a “Data Map Name” highlighted by yellow in the above screen shot.

image
Click on finish. Check the record on completion of the import process.

I have attached the sample zip file here. Download it and import into your system to test it.

Monday, June 11, 2012

How to display an entity form based on the option set field (Multiple forms CRM2011)

Sometimes we need multiple forms based on categorisation of an entity. For example, an account can be  a customer or a competitor or a supplier etc. It is possible that we need to capture or display different fields based on the type of an account. Suppose we have different forms  for different types of account. If the user opens an account record, the system should open a appropriate form based on the type of the account.
In this example I am using account entity. I have created 2 custom forms. Now I have 3 account forms (Information, Information1, Information2). In out of the box account entity . there is a “Relationship Type” or customertypecode field to categorise the account entity. It is picklist field. I want to open a different form based on the value of the customertypecode field . Here is the code.
function showForm() {

//if the form is update form
if (Xrm.Page.ui.getFormType()==2)
    // variable to store the name of the form
    var lblForm;

    // get the value picklist field
    var relType = Xrm.Page.getAttribute("customertypecode").getValue();

    // switch statement to assign the form to the picklist value
    //change the switch statement based on the forms numbers and picklist values
    switch (relType) {
        case 1:
            lblForm = "Information1";
            break;
        case 2:
            lblForm = "Information2";
            break;
        default:
            lblForm = "Information";
    }
    //check if the current form is form need to be displayed based on the value
    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
        var items = Xrm.Page.ui.formSelector.items.get();
        for (var i in items) {
            var item = items[i];
            var itemId = item.getId();
            var itemLabel = item.getLabel()

            if (itemLabel == lblForm) {
                //navigate to the form
                item.navigate();
            } //endif
        } //end for
    } //endif
 }//endif
} //end function
The code is checking if the form is an  “Update” form and opens up the form based on the value of customertypecode field. The code is reloading the form only if the current form is different than the form the system should be displaying.
Call this function on form load event.
Happy programming…