Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, January 4, 2011

CRM 4 to CRM 2011 Upgrade.

Recently we tried to upgrade a highly customized CRM 4 install to CRM 2011 and thought it would be worthwhile to list out our findings for the benefit for all.

CRM 2011 supports both in-place upgrade as well as a fresh CRM 2011 install with a later CRM 4.0 organization import into CRM 2011. We attempted the second way, that a fresh install of CRM 2011 and then tried to import the customized organization of CRM 4.0.

If you install the CRM 2011 beta copy and try the import you will receive the following error.

…lead.Address1 Country length 160 more than original value 100…

This appears to be a bug of the beta version that is probably rectified in the CRM 2011 RC released recently.

After a successful install, you can try to import the CRM 4.0 organization, it auto detects that it is an upgrade and would performs all the necessary operations on the database. Make sure you have another backup of the CRM 4.0 in case the upgrade fails mid-way you will need to go back and restore the original copy and start over again.

After a successful upgrade we found the following items we auto-upgraded to CRM 2011 standards by the upgrade tool.

Scripts:

All the scripts written on form save, load and Change will be automatically converted into web Resource and saved as Library with the name Entityname_main .see the display name below.
Select any Web Resource it looks as shown below.


On click of Form properties for any entity you will find that library is already added on the form and it is called on load event with function name.


The code written on the Load event would be put into a function named Form_onload. The OnSave event is changed to function named Form_onsave and Onchange becomes
Attributename_onchange.

Images:

All the Images used in the Custom entities will be saved as Web resource.

ISV buttons:

Any script written on custom button added through ISV in CRM will be converted to Application Ribbons. Buttons of CRM 4.0 are moved to Ribbons in CRM 2011 as shown below.

Plugins:

Plug-in registered in the CRM for entities will be saved as Plug –In Assemblies and Sdk Message Processing

Plug –In Assemblies shows Name ,Version, Culture Public Key Token and the date on which it was created and last modified date.

Sdk Message Processing shows Message, Event Handler, object type code ,Stage and Status

Workflow:

The Workflows would be auto-upgraded as Processes in CRM 2011 as can be seen from the screenshot below


Form Layout

The form layout is carried over as is during the upgrade from CRM 4.0 to CRM 2011. We however found a conflicts tab added to a couple of forms but were unable to trace the controls placed in this section to any of the controls in the original CRM 4 form.

There are sure to be many more items that were upgraded behind the scenes and we will update the list in times to come. However this is a pretty good reference point to start with for a CRM 4 to 2011 upgrade.

Thursday, January 7, 2010

Debugging Script with CRM events

Writing JavaScript in CRM is a tedious job and finding the error in your script is even more difficult. The best way to find the error cause is to debug it. The blog will give you the steps to debug the scripts added on form events in CRM.

Steps to enable debugging script:

- Go to Internet Explorer settings.
- Click on Tools and select Internet Options. You will we see following screen.


- On the Advanced Tab, under Browsing find the Disable script debugging (Internet Explorer) option and uncheck it.
- In the script use “Debugger”, just before the statement where you want to start your debugging session.
- For example: you can write script under the CRM events such as onLoad, Onsave etc.
debugger;
//after start to write script
- After add script ,save it and publish. Refresh the page, you will see following screen.


- Select new instance of visual studio 2008/2005 and click on yes. After this open script code on visual studio for debugging mode where you can debug own script. (See below the screen)

Monday, September 14, 2009

Add Shortcut button for new Activity on CRM toolbar

Some time back we had posted a script that would allow you to create an ISV button to bring up the new activity form (phone call, appointment etc).

Recently we had the same request from one of our customers and we were quick to offer them the same. Unfortunately it failed. The locAddActTo function is not available on main CRM form.

To get this done, we had to provide the following alternate script


<Button Icon="/_imgs/ico_16_4210_d.gif" JavaScript="window.open('/activities/phone/edit.aspx','null','height=500px,width=800px,resizable=1,status=yes,toolbar=no,menubar=no,location=no')"> <Titles> <Title LCID="1033" Text="New Phonecall" /> </Titles> <ToolTips> <ToolTip LCID="1033" Text="Create New Phonecall" /> </ToolTips>

</Button>

Sunday, June 7, 2009

Call Workflow from ISV button

We had once given an option to one of our customers to perform an action using on-demand workflow. We provided them with the steps to run the workflow from the "Run Workflow..." button that is added to the entity in case and entity has on-demand workflows published against them.

The customer however wanted that we add a button with a descriptive lable that performed the job so that the users are not burdened with having to select the correct workflow from the list and it was a one-click solution.

We found that CRM has an inbuilt function made available that calls the workflow "launchOnDemandWorkflow"

The syntax of the function is
launchOnDemandWorkflow('crmGrid',ObjectTypeCode,Workflow ID) //when called from grid

launchOnDemandWorkflow('',ObjectTypeCode,Workflow ID) //when called from entity form

This function has 3 parameters.
The first one is left blank only if the button is on the record of that entity and workflow needs to be called on that record only. whereas, if the button is placed on the grid of CRM entity view then first parameter should be 'crmGrid' so that the workflow will get called for the records selected in that view.


Second parameter contains object type code of that entity

Third parameter is the id of the workflow to be fired

To get the workflow id, follow the below steps.

1. Go to Setting --> Workflow form.
2. Here open the workflow that you want to run on button click.
3. Now press "Ctrl + N" which will open the same page in the IE.
4. In the Address bar of IE you can find the id of workflow.

This should help provide users with the most familiar option of clicking a button to perform an action.

Friday, February 27, 2009

List of Events available to trap in Scripts when saving a Dynamics CRM Form

CRM 3.0 has limited event detection made available using scripting. However It is now possible to detect which user action was performed to Save the form using the event.Mode property in the OnSave event.

You can gain more detailed information about the user actions in the OnSave event by referencing the event.Mode values. These values represent the buttons clicked by the user to save the record.

The following event modes are supported:

EntityEvent ModeValue
AllSave1
AllSave and Close2
AllSave and New59
Task, Phone Call, Letter, Fax, AppointmentSave as Completed58
AllDeactivate5
AllReactivate6
Alluser-owned entities Assign 47
E-MailSend7
LeadQualify 16
LeadDisqualify15

By checking the value of event.mode we can find out which button user has clicked and based on this take further action.

To cancel the Save operation event simply use the script below:
event.returnValue = false;

Tuesday, February 24, 2009

Bulk Edit records of any entity in CRM

We can easily edit a record in crm. But what if we need to edit a field of all records with same value. So here, Instead of opening records one by one and editing it, we can also use Bulk edit feature which edits that field in one go for all records.

For some records like account,contact ,lead, Product etc, there is already an in-built feature for bulk editing these records.

Below we have explained how to bulk edit the account records :


  1. Select all the records for which you need to edit fields in bulk. We have selected all the account records as shown in the screen below:


2. Now go to More actions and click on edit.



3. Then you will get the window as shown in the screen below. Here, you can edit any field which will be applied to all the selected records. We have edited the account name.




4. Only when you save this form, you will find that all the selected records have been edited with that value. Here we edited account name and all the account names of selected records will be test as shown in the screen below :




This is how Bulk edit of account entity works.

Note :- CRM does not support bulk edit for all entities like Activities ,SalesOrder.

But, if you want to Bulk edit records of Activities ,salesorder which are not supported by CRM then we can do this also.

For this, you will have to write a JavaScript on “ISV Button” and place that button on the particular entity where bulk edit feature is desired.

In that script we have to call a function which is :

“doAction('crmGrid', 'entitytypecode', 'bulkedit')”

Below is a code for adding a button for bulk editing Appointment records which will be added in the isv.config :

//Start of Script

<Entity name="activitypointer">//You can change the entity name

<Grid>

<MenuBar>

<Buttons>

<Button Icon="/_imgs/ico_18_debug.gif" JavaScript="doAction('crmGrid', '4201', 'bulkedit');" Client="Web">

//”4201” is the entity type code of Appointment

<Titles>

<Title LCID="1033" Text="Bulk Edit" />

</Titles>

<ToolTips>

<ToolTip LCID="1033" Text="Bulk Edit." />

</ToolTips>

</Button>

</Buttons>

</MenuBar>

</Grid>

</Entity>

//End of Script


We have to only change the entitytypecode according to the entities required for bulk edit.

For example : If we want to bulk edit “Salesorder” then we have to write doAction function as follows:

“doAction('crmGrid', '1088', 'bulkedit')” where "1088" is the entitytypecode of salesorder entity.
We can also bulk edit the records for entities like phonecall,email etc by changing their respective entitytype codes in the doAction function.

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!

Monday, February 16, 2009

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.