Friday, February 20, 2009

Automatically resize the IFRAME to adjust to the Form size

If you need to show an external page within CRM, you need to provide the URL to the IFRAME in CRM. You will notice that it would not display scrollbars to scroll through the entire web page being displayed in the IFRAME. So it is advised that we create a custom page and add an IFRAME within a "DIV" tag. This helps in bringing up the Scroll bars to allow users to navigate through the entire page.

But there is still a glitch. If you happen to resize the form on which the IFRAME has been added, you will find that the IFRAME does not automatically resize itself according to the form.

Here is the script that we used to achieve this.

Here we try to resize the two IFRAMES ('IFRAME_ActivityShow' and 'IFRAME_ReportShow') that were added on the CRM form.

Add the below function in the custom page on which the IFRAME has been originally placed


function calcHeightWidth()

{

var main_height = null;

var main_width = null;

var height = null;

var width = null;



// for all except Explorer

if (self.innerHeight) {

main_height = self.innerHeight;

main_width = self.innerWidth;

// Explorer 6 Strict Mode

} else if (document.documentElement

&& document.documentElement.clientHeight) {

main_width = document.documentElement.clientWidth;

main_height = document.documentElement.clientHeight;

// other Explorers

} else if (document.body) {

main_height = document.body.clientHeight;

main_width = document.body.clientWidth;

}



height = main_height * (3/4) + 'px';

width = main_width * (1/2) + 'px';



//change the height of the iframe

document.getElementById('IFRAME_ActivityShow').style.height=height;

document.getElementById('IFRAME_ActivityShow').style.width=width;

document.getElementById('IFRAME_ReportShow').style.height=height;

document.getElementById('IFRAME_ReportShow').style.width=width;

}


We need to attach this function to the IFRAME in the page load event of the custom page.

if (!Page.IsPostBack)
{
IFRAME_ActivityShow.Attributes.Add("onload","javascript:calcHeightWidth()");

}

Hope this helps others too!

Wednesday, February 18, 2009

Design a workflow for performing repetitive tasks

Sometimes, there is a need to perform a particular task or action repetitively over a period of time. We were in a need to create a task activity after every 2 days against an account.

This can be done by creating child workflow and call it from the parent workflow. The child workflow would peform the actual job and the parent will call this child recurrsively.

Here are the steps to get this done:
  1. Create a workflow for required entity (For eg: account) with following triggers
    - On demand
    - As a child workflow
    - Record is created
  2. Set the scope of the Workflow as appropriate (For eg: organization)
  3. Now the structure of workflow will be as follows:

First is wait condition which says, wait for 2 days after the execution of this workflow. This condition is as shown below:

After this condition is fulfilled, a task is created and then again child workflow is started which is the same workflow created above (i.e. test recurring). So, the workflow runs recursively and creates a task after every 2 days.

Monday, February 16, 2009

Shortcut to open any record in CRM

There are a couple of generic urls that would let you open any type of record in CRM

  • If you need to open any type of record but don't know the URL. No worries just specify object type code (you can get object type code from CRM SDK under section" Entity Type Codes") and ID it will open your record. (Note that the parameter names are case sensitive here)

http://server:port/organization/CRMReports/viewer/drillopen.aspx?ID=objectid&OTC=objecttypecode

  • To open a record in ReadOnly mode

http://server:port/organization/_forms/readonly/readonly.aspx?objTypeCode=objecttypecode&id=objectid

You can call these from anywhere in CRM and it will identify the entity and open the relevant entity form. This does away the need or specifying url specific to the entity.

Shortcut to create activities for an account or contact

CRM Forms already have a button to quickly send an email. The "Follow up" button allows you to quickly create activities, however it does not show up the entire activity form.
If you instead wanted a way to create a task or some other activity and want the activity form to show-up without navigating to the Activities pane and click on New and select the appropriate entity, here is the code that will help


  • Send Email: locAddActTo(4202); // where 4202 = objecttypecode

  • Create Task: locAddActTo(4212)

The entire list of ObjectTypeCode for all entities in CRM can be found in the SDK

Friday, February 13, 2009

Shortcut to Add notes and attachments

You need to navigate to the Notes tab each time you need to add a note. Also the shortcut to add a quick note in CRM does not show up the note form that allows to fill in all details including subject and attachment in one go. If you want to add all information to the note it would involve atleast a couple or more of clicks to get all done.
You can add convenient shortcuts to add notes without having to navigate to the Notes tab and save a few clicks.


  • add a note : locAddObjTo(5); This will open up the new note form

  • attach a file : locAddFileTo(5); This will bring up the attach file form.