Welcome to our website

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ed ut perspiciatis unde omnis iste.

Posts mit dem Label JavaScript und CRM 2011 werden angezeigt. Alle Posts anzeigen
Posts mit dem Label JavaScript und CRM 2011 werden angezeigt. Alle Posts anzeigen

Mittwoch, 11. Januar 2012

CRM 2011 – Hilfreiche JavaScript Codeschnipsel


http://www.dynamicsconsulting.de/2012/01/11/crm-2011-hilfreiche-javascript-codeschnipsel/

Mit CRM 2011 hat sich das Objektmodell für JavaScript geändert. Hier findet ihr ein paar hilfreiche Codeschnipsel für CRM 2011.
CRM 2011 – Hilfreiche JavaScript Codeschnipsel CRM 2011 – Hilfreiche JavaScript Codeschnipsel
CRM 2011 – Hilfreiche JavaScript Codeschnipsel CRM 2011 – Hilfreiche JavaScript Codeschnipsel

Den Wert eines Feldes auslesen
Xrm.Page.getAttribute(“Feldname”).getValue() ;
Den Wert eines Feldes setzen
Xrm.Page.getAttribute(“Feldname”).setValue(‘NeuerWert’);
Den Wert eines Lookup-Feldes auslesenvar lookup = new Array();
lookup = Xrm.Page.getAttribute(„Feldname“).getValue();
lookup[0].id;
lookup[0].name;
lookup[0].entityType
Den Wert eines Lookup-Feldes setzenvar lookup = new Array();
lookup[0] = new Object();
lookup[0].id = ‘GUID des Datensatzes’;
lookup[0].name = ‘Name des Datensatzes’
lookup[0].entityType = typeValue;
Xrm.Page.getAttribute(„Feldnam“).setValue(lookup);
Auswahl der Entitäten im Lookup einschränken
document.getElementById(„customerid“).setAttribute(„lookuptypes“, „1″);
Ein Feld anzeigen/versteckenXrm.Page.ui.tabs.get(„Feldname“).setVisible(false);
Xrm.Page.ui.tabs.get(„Feldname“).setVisible(true);
Eine Sektion (Tab) anzeigen/verstecken
Xrm.Page.ui.tabs.get(2).setVisible(false);
Xrm.Page.ui.tabs.get(2).setVisible(true);
Anstelle des Indexes für den Tab kann auch der Name des Tabs verwendet werden
Das OnChange Ereignis eines Feldes aufrufen
Xrm.Page.getAttribute(“Feldname”).fireOnChange();
Den ausgewählten Eintrag einer Pickliste auslesen
Xrm.Page.getAttribute(“Feldname”).getSelectedOption().text;
Den Wert einer Pickliste setzenXrm.Page.getAttribute(„Feldname“).setValue(parseInt(Wert));
Den Level setzen
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“recommended”);
Focus auf ein Feld setzen
Xrm.Page.getControl(“Feldname”).setFocus(true);
OnSave Ereignis abbrechen
event.returnValue = false;

=============================================
http://www.dynamicsconsulting.de/2012/01/11/crm-2011-hilfreiche-javascript-codeschnipsel/

CRM 2011 Useful JavaScript tidbits

One of the noticeable changes between CRM 4 and CRM 2011 is the JavaScript object model. It has changed a bit. Below are some of the commonly used functions used to manipulate CRM forms. Let us know if you have a commonly used function that should be included in the list below.
One of the tools we highly recommend is the JavaScript CRM 4 to CRM 2011 converter tool:
http://crm2011scriptconvert.codeplex.com/ Here are common tidbits:

Get the value from a CRM field

var varMyValue = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue() ;

Set the value of a CRM field

Xrm.Page.getAttribute(“po_CRMFieldSchemaName”).setValue(‘My New Value’);

Hide/Show a tab/section

Xrm.Page.ui.tabs.get(5).SetVisible(false); Xrm.Page.ui.tabs.get(5).SetVisible(true);

Call the onchange event of a field

Xrm.Page.getAttribute(“CRMFieldSchemaName”).fireOnChange();

Get the selected value of picklist

Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;

Set the requirement level

Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“none”); Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“required”); Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“recommended”);

Set the focus to a field

Xrm.Page.getControl(“CRMFieldSchemaName”).setFocus(true);

Stop an on save event

event.returnValue = false;

Return array of strings of users security role GUIDs:

Xrm.Page.context.getUserRoles()

Hide/Show Tabs and Sections

function setVisibleTabSection(tabname, sectionname, show) {
    var tab = Xrm.Page.ui.tabs.get(tabname);
    if (tab != null) {
        if (sectionname == null)
            tab.setVisible(show);
        else {
            var section = tab.sections.get(sectionname);
            if (section != null) {
                section.setVisible(show);
                if (show)
                    tab.setVisible(show);
            }
        }
    }
}

http://www.dynamicsconsulting.de/2012/01/11/crm-2011-hilfreiche-javascript-codeschnipsel/

Microsoft Dynamics CRM 2011 Objektmodell für JavaScript

Mit CRM 2011 hat sich das Objektmodell für JavaScript geändert. Hier findet ihr ein paar hilfreiche Codeschnipsel für CRM 2011.
Den Wert eines Feldes auslesen
Xrm.Page.getAttribute(“Feldname”).getValue() ;
Den Wert eines Feldes setzen
Xrm.Page.getAttribute(“Feldname”).setValue(‘NeuerWert’);
Den Wert eines Lookup-Feldes auslesenvar lookup = new Array();
lookup = Xrm.Page.getAttribute(„Feldname“).getValue();
lookup[0].id;
lookup[0].name;
lookup[0].entityType
Den Wert eines Lookup-Feldes setzenvar lookup = new Array();
lookup[0] = new Object();
lookup[0].id = ‘GUID des Datensatzes’;
lookup[0].name = ‘Name des Datensatzes’
lookup[0].entityType = typeValue;
Xrm.Page.getAttribute(„Feldnam“).setValue(lookup);
Auswahl der Entitäten im Lookup einschränken
document.getElementById(„customerid“).setAttribute(„lookuptypes“, „1″);
Ein Feld anzeigen/versteckenXrm.Page.ui.tabs.get(„Feldname“).setVisible(false);
Xrm.Page.ui.tabs.get(„Feldname“).setVisible(true);
Eine Sektion (Tab) anzeigen/verstecken
Xrm.Page.ui.tabs.get(2).setVisible(false);
Xrm.Page.ui.tabs.get(2).setVisible(true);
Anstelle des Indexes für den Tab kann auch der Name des Tabs verwendet werden
Das OnChange Ereignis eines Feldes aufrufen
Xrm.Page.getAttribute(“Feldname”).fireOnChange();
Den ausgewählten Eintrag einer Pickliste auslesen
Xrm.Page.getAttribute(“Feldname”).getSelectedOption().text;
Den Wert einer Pickliste setzenXrm.Page.getAttribute(„Feldname“).setValue(parseInt(Wert));
Den Level setzen
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“recommended”);
Focus auf ein Feld setzen
Xrm.Page.getControl(“Feldname”).setFocus(true);
OnSave Ereignis abbrechen
event.returnValue = false;

Donnerstag, 16. Juni 2011


Project Description
CRM 4 to CRM 2011 Javascript Converter helps convert scripts to the latest CRM 2011 Form scripting model. The converter uses an xml file that contains CRM4 and CRM5 nodes which allow the converter to find/replace specific instances of text. For further details please see the documentation area.

Usage
Simply paste your CRM 4 script into the left hand text area and click Convert.
CRM 4 to CRM 2011 Converter Tool

CRM 2011 – JScript IntelliSense for Form Script Libraries in version 5.0.3

CRM 2011 – JScript IntelliSense for Form Script Libraries in version 5.0.3



A fantastic blog entry from the Microsoft Dynamics CRM blog today about Jscript Intellisense for Form Script Libraries, click here to read it. Sometimes I wonder why you need to keep updating your version of CRM 2011 but then when I read the goodies they have added into the latest version, I then want to upgrade.
The blog post also led me to a page I hadn’t seen JScript Intellisense Overview and it also has an interesting page Walkthrough:Jscript Intellisense
it is a really in depth blog entry about how they added in JScript Intellisense with the new release of SDK 5.03, here is a brief quote from the blog post
In the latest release of the Microsoft Dynamics SDK (Version 5.0.3) you will find a Microsoft Dynamics CRM Solution and Visual Studio extension that together will provide IntelliSense support for the Xrm.Page object in form scripts. I hope that this solution will help make your process of creating form scripts using the Xrm.Page object more productive. The result is that you can have IntelliSense that provides auto completion and documentation about the methods as shown below:
image
The SDK\Templates\Xrm.PageScriptProjectTemplate\Readme.docx file in the download package provides details about installing and using the solution. Rather than repeat what you can find there, in this post I will describe the process of creating this solution and I hope to set your expectations for what the solution offers.

Re-usable JScript Libraries in Dynamics CRM 2011

Re-usable JScript Libraries in Dynamics CRM 2011

Introduction: Web Resources and JScript Libraries

One of the most remarkable improvements in Dynamics CRM 2011 is the broadened scope for “declarative customizations” – i.e., those not requiring code. If you’re just starting out with the new version and have some customization experience with CRM 4.0, a good place to see this is in working with lookups. Nearly every day I discover a useful application that required code in CRM 4.0 but can be done in CRM 2011 entirely by customizing properties of the new and improved lookup field.
Topics like the one I present here are covered in my subscription series of 4-hour training sessions, Dynamics CRM 2011 Essentials. Find out more and register here…
For example, check out the code required to create a filtered lookup in CRM 4.0 and then compare it to the no-code-form-editor-only approach in CRM 2011 (the latter example is illustrated in the demo at the end of the article).
That being said…there are still plenty of situations requiring some code. Fortunately, when you run into one of these, the improvements in CRM 2011 are just as significant. The ones I want to talk about here – re-usable libraries of JScript code – are part of a brand-new construct known as a “web resource”. Think of web resources as virtual files: resources that can be stored in the CRM 2011 database that in CRM 4.0 would have required a physical disk file. I presented an introductory session at the recent Extreme 2010 show on web resources, and wrote up a summary article here.
In this article I return to the “useful CRM form scripts” theme of the articles you’ll find this in the Trick Bag’s form scripts category: this article is effectively the “hello world” version of working with form scripts in CRM 2011. My experience is that the CRM 2011 approach is different enough from CRM 4.0 that there’s a short, sharp learning curve; hopefully this article will help. The good news is, once you get used to working with JScript web resources, you’ll find that the benefits of having re-usable libraries of form script functions will far outweigh the costs of learning how they work!
If you ever wrote CRM 4.0 form script to turn a phone number entered like this – 6306667667 – into something like this – (630)666-7667 – you probably started by grabbing code from somewhere on the web or something you’d written previously, and placing it on the Change event of the phone number field on a form. The account entity has ten phone number fields (including fax numbers) and the contact entity (including pager numbers) probably has more. So if you implemented this on 20 fields and then had to fix a bug…you had your work cut out for you!
There were techniques in CRM 4.0 to make this a little easier:
  1. You could place a single function in the load event of a form and then call that function from the change event of a form field.
  2. You could actually create a library of re-usable JScript functions, placed by convention in the ISV folder on your CRM server.
Both of these had problems, though: The first one only works for a single entity, so you’d still have to make changes in multiple places. The second involved a fair amount of plumbing to set it up, and created a pretty serious feature gap between CRM Online and on-premise.
In the next section I’ll focus on the mechanics of creating JScript libraries and calling their functions; if you already know the basics and want to see the FormatPhoneNumber bit, skip to the following section.

Example: CRM 2011 Hello World

How do you create your first JScript library and call a function? Here’s a step-by-step hello world example, assuming you’re a user with something like the System Administrator security role:
  1. On the site map, click Settings, and then click Customizations.
  2. On the Customizations page, click Customize the System.
  3. In left navigation, click Web Resources, and then click New.
  4. In the Web Resource dialog, type a Name and a Display Name. (The Name is the schema name, so it can’t have spaces or special characters.)
  5. In the Type drop-down, select Script, and then click Save.

    At this point you can browse out to disk and upload a file if you have one. If you’re just starting out, however, you might not have one that will work, because the new object model in CRM 2011 requires some slight differences in the JScript code. In any event, this is the “hello world” example, so I’ll take a shortcut:
  6. Rather than uploading a file, you can simply click the Text Editor button to open up the default editor. What you’re creating in here is the function that will be called from a form event – that is, will be identified as the “event handler” for a form event. To focus specifically on the mechanics, here’s as simple an example as I can come up with:



    This shows what it might look like after you clicked the Text Editor button and wrote your function.
  7. Click OK to save the function, then click Save & Close in the Web Resource window.
  8. Web resources need to be published in order to use them, so with your web resource selected in the list, click Publish on the toolbar.
Now that your function’s ready to use, how do you use it? To illustrate the point that functions contained within a Script web resource are re-usable across any entity form in your CRM, I’ll do the next step-by-step generically. Just think: with the exact same code you can provide your users a cheery greeting regardless of which entity’s form they happen to be opening!!! J

  1. Navigate to the grid for any record type, and click the Customize tab on the ribbon.
  2. In the Design group, click Form. The form editor opens.
  3. Click Form Properties in the Form group.
  4. In the Form Libraries section, click Add. The Look Up Record dialog should appear and you should see your JScript library. (This lookup is context sensitive and in this context knows the only kind of web resource that can go here is a JScript library.) In my example, it looks like this:


  5. Select it and click OK. All functions contained in that library are now available as event handlers for any control on the form. (You can have multiple form libraries for a single form, as well as multiple handlers for a single control on the form.)
  6. To call the function, scroll down to the Event Handlers section. Click the Control drop-down, and notice that you can select ANY control on the form right from here: even though this dialog is for form properties, you aren’t restricted to only accessing the OnLoad and OnChange events for the form as in CRM 4.0
  7. But for this example, I’ll stick to the form load: select Form in the Control list, OnLoad in the Event list, and then click the Add button.
  8. You need to type the name of the function (remember JScript is case-sensitive) in the Function field, and then click the Enabled checkbox:


  9. Now click OK, then OK again to close out the Form Properties dialog. Preview the function from within the form editor to see how it works.

Example: FormatPhoneNumber

OK, now that we’ve seen how the mechanics work, let’s do something useful! For the step-by-step example I’ll do next, I’m going to take a slightly different approach that will end up with the same result: I’ll start out from the account form, and create the JScript Library web resource on the fly, illustrating another good example of “in-place” customization. But the library I create will be equally accessible from any entity in CRM, and the FormatPhoneNumber function is written so it can be called from any phone number field.
  1. Navigate to the accounts grid, and click the Customize tab on the ribbon.
  2. In the Design group, click Form.
  3. In the Form group, click Form Properties, and then in the Form Properties dialog, click Add in the Form Libraries section.
  4. In the Look Up Record dialog, click New. (This is the “creating it on the fly” part.) The Web Resource: New window appears. I’ll call mine “CommonFunctions”, with an appropriate Display Name, select Script (JScript) in the Type drop-down, and then click Save:

Click Text Editor, and enter the code you see in the following screenshot:

A couple quick points about this JScript function:

A couple quick points about this JScript function:
  • Even if I have a disk file I could upload, it’s just as easy to copy it to the clipboard and then paste it into the editor.
  • Notice the “context” parameter. This is important if the function is intended for re-use; you’ll see that in a minute when we call it as an event handler.

  1. Click OK to save the function, and then click Publish in the Actions group on the Web Resource ribbon. Even though I did this from within Account, it will be published as a web resource available from anywhere. Then click Save and Close to close out of the web resource window, and you should be back in the Look Up Record dialog (remember? From step 4 above.)
  2. Then select the function library and click OK, and you should be back on the Form Properties dialog, with your function library added as an available library:


    Now you have a couple options: you can either click OK to return to the form editor and locate the phone number fields you want to use the function on, OR do it the cool new time-saving way I’ll do here:
  3. Keep the Form Properties dialog open and select Main Phone in the control list.
  4. Then click Add in the Event Handlers section to open the Handler Properties dialog.
  5. Type the function name – FormatPhoneNumber – in the Function field, click the Enabled checkbox, and make sure this time to click the Pass execution context as first parameter checkbox:

  6. Now click OK, and then OK again.
  7. Preview the form and test how it works. Since I added the event handler to the change event of the Main Phone field, I’ll do my testing on that one: I’m scolded if I don’t enter a 10-character phone number, and if I do enter one I’m rewarded with a nice standard phone number format. (as long as you’re talking about US phone numbers, anyway!)
  8. Of course, the payoff is that you can now navigate to any entity and use the same function to provide formatting for any phone number field. After you finish off the account form, go to contacts, then leads, and so on.
  9. And by the way: if you get all the way to step 12 and nothing happens, navigate to the web resource through the customization UI (Settings, Customizations, Customize the System, Web Resources) and publish the library of functions. I’ve had intermittent success with the shortcut approach I took here (where I published in step 6 after doing the “in-place” customization approach.) I believe it should work like that but sometimes it seems like it … doesn’t… quite. Anyway, that’s what betas are for.
  10. …and in conclusion…

  11. I meant to record a demo of this so you could get a feel for how much time this can save you. But I ran out of time: my wife told me all she wants for Christmas is a one-second needle and I’m afraid Walgreens will already have run out! I hope you got your shopping done. Merry Christmas and season’s greetings to you & yours – I’ve got to go look for a one-second needle.

Useful Form Scripts, CRM 2011 Style

Useful Form Scripts, CRM 2011 Style

The style of JScript we need to write for Dynamics CRM 2011 has changed significantly in the upgrade from CRM 4.0. If you learn best from examples, here are a few you may find helpful. If you’re just starting out and need to figure out some of the basic stuff like how you add functions to function libraries, and how you add a function library to form properties, here’s an intro article I wrote on the topic.
This article is in more of a summary style — let me know what you think of the format.
Function ShowAccountTabs()
Illustrates hiding and showing tabs , based on selected value of option set
- Contained in function library added to Account form
- Requires two custom tabs, named “customer” and “competitor”
- Tab labels can be anything you want
- function added as event handler for the system option set, customertypecode, (default label Relationship Type)
Function Listing:
function ShowAccountTabs() {
   if (Xrm.Page.getAttribute("customertypecode").getValue() != null ) {
var RelationshipType = Xrm.Page.getAttribute("customertypecode").getSelectedOption().text;
if (RelationshipType == "Customer") {
         Xrm.Page.ui.tabs.get("customer").setVisible(true);
         Xrm.Page.ui.tabs.get("competitor").setVisible(false);
      }     
      else if (RelationshipType == "Competitor") {
         Xrm.Page.ui.tabs.get("customer").setVisible(false);
         Xrm.Page.ui.tabs.get("competitor").setVisible(true);
      }
      else {
         Xrm.Page.ui.tabs.get("customer").setVisible(false);
         Xrm.Page.ui.tabs.get("competitor").setVisible(false);
      }
   }
}
Function CreateOpportunityURL()
Creates a clickable link (URL) for an opportunity record. Useful to include in a workflow-generated email. (Remember: if they aren’t using the Outlook client, the “Regarding” field won’t be clickable.
- Contained in function library added as handler to Opportunity form
- Added as event handler to OnSave event
- Requires custom field for URL, prefix_url
- Current code requires record to be saved once so that GUID exists
Function listing:
function CreateOpportunityURL()
{
   var opportunityid = Xrm.Page.data.entity.getId();
if (opportunityid!= null) {
      if (Xrm.Page.getAttribute("rgk_url").getValue() == null)
      {
         var serverurl = Xrm.Page.context.getServerUrl();
         var recordurl = serverurl+"main.aspx?etn=opportunity&id=";
         var strtemp = opportunityid.replace("{", "%7b");
         var strtemp = strtemp.replace("}", "%7d");
         recordurl += strtemp;
         recordurl += "&pagetype=entityrecord";
         Xrm.Page.getAttribute("rgk_url").setValue(recordurl) ;
      }
   }
}
Function DisplayWebSiteinIFrame()
- Contained in function library added to Account form
- Event handler for custom option set, <prefix>_website, with two values, “SharePoint” and “Bing Maps”
- Depending on which is selected, updates IFRAME_selectedwebsite with dynamically created URL
- For SharePoint search URL, replace “https://sp.magenium.com” with your organization’s SharePoint site
Function listing:
function DisplayWebSiteInIFrame()
{
 if (Xrm.Page.getAttribute("rgk_website").getSelectedOption().text != null) {
var selectedwebsite = Xrm.Page.getAttribute("rgk_website").getSelectedOption().text;
var IFrame = Xrm.Page.ui.controls.get("IFRAME_selectedwebsite");
var Address = Xrm.Page.getAttribute("address1_line1").getValue();
   Address = Address + " " + Xrm.Page.getAttribute("address1_city").getValue();
   Address = Address + " " + Xrm.Page.getAttribute("address1_stateorprovince").getValue();    
switch(selectedwebsite)
   {
      case "SharePoint" :
         IFrame.setSrc("https://sp.magenium.com/search/Pages/Results.aspx?k=" + Xrm.Page.getAttribute("name").getValue() );
         break;
case "Bing Maps" :
         IFrame.setSrc("http://www.bing.com/maps/?q=" + Address);
         break;
   }
 }
}

Sonntag, 20. März 2011

Microsoft Dynamics CRM 2011 - Objektmodell - JavaScript - Codeschnipsel - Java Sciptcode für Dynamics CRM 2011

Mit CRM 2011 hat sich das Objektmodell für JavaScript geändert. Hier findet ihr ein paar hilfreiche Codeschnipsel für CRM 2011.
Den Wert eines Feldes auslesen
Xrm.Page.getAttribute(“Feldname”).getValue() ;

Den Wert eines Feldes setzen
Xrm.Page.getAttribute(“Feldname”).setValue(‘NeuerWert’);

Den Wert eines Lookup-Feldes auslesenvar lookup = new Array();
lookup = Xrm.Page.getAttribute(„Feldname“).getValue();
lookup[0].id;
lookup[0].name;
lookup[0].entityType

Den Wert eines Lookup-Feldes setzenvar lookup = new Array();
lookup[0] = new Object();
lookup[0].id = ‘GUID des Datensatzes’;
lookup[0].name = ‘Name des Datensatzes’
lookup[0].entityType = typeValue;
Xrm.Page.getAttribute(„Feldnam“).setValue(lookup);

Ein Feld anzeigen/versteckenXrm.Page.ui.tabs.get(„Feldname“).setVisible(false);
Xrm.Page.ui.tabs.get(„Feldname“).setVisible(true);

Eine Sektion (Tab) anzeigen/verstecken
Xrm.Page.ui.tabs.get(2).setVisible(false);
Xrm.Page.ui.tabs.get(2).setVisible(true);

Anstelle des Indexes für den Tab kann auch der Name des Tabs verwendet werden
Das OnChange Ereignis eines Feldes aufrufen
Xrm.Page.getAttribute(“Feldname”).fireOnChange();

Den ausgewählten Eintrag einer Pickliste auslesen
Xrm.Page.getAttribute(“Feldname”).getSelectedOption().text;

Den Wert einer Pickliste setzenXrm.Page.getAttribute(„Feldname“).setValue(parseInt(Wert));
Den Level setzen
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“Feldname”).setRequiredLevel(“recommended”);

Focus auf ein Feld setzen
Xrm.Page.getControl(“Feldname”).setFocus(true);

OnSave Ereignis abbrechen
event.returnValue = false;

Samstag, 19. Februar 2011

Form Scripting with Microsoft Dynamics CRM 2011

Form Scripting with Microsoft Dynamics CRM 2011
The ability to insert Javascript into Client-side Events was one of the most common ways of extending MSCRM’s functionality, allowing bespoke logic to be implemented with a small amount of development effort. This largely acted as mid-way development between Functional Customisation and more Technical Development for Server-side Plugins and Custom Workflow Actions.
However this ability to add Javascript was restricted in not being able to easily use Include Statements to incorporate Function Libraries containing common methods that the scripting could make use of across the solution – and this in turn gave rise to larger streams of Javascript on events, which could make for some unmanageable coding. (and indeed occasionally some of this, Copy and Paste Programming)
The Designers of CRM 2011 have clearly given thought to this problem and incorporated a system for attaching Javascript Libraries into CRM as Web Resources that individual CRM Events (such as Account onLoad or a particular field’s onChange) can invoke functions from.
This concept of having a Javascript Library is one that I have been advocating for a few years as way of encouraging MSCRM Developers to include their javascript files into a Visual Studio Project such that we could manage version control and source control – CRM 2011 is a big step forward to making this mandatory for including almost any Javascript in a project. This does give a natural downside in making the process for incorporating Javascript slightly more complex for people working with MSCRM, and particularly training Clients on the SDK, but this looks to be a trade-off that is common across CRM 2011 as the application comes of age.
To look at this in practise, the following steps show how to incorporate a simple helloWorld style method into the onLoad event of an Account in CRM 2011.
(1) First of all – we customise the entity in question to bring up Form Customisation.
Account Customisation - Form
Customising the Account entity form in CRM 2011
(2) Clicking Form Properties then opens a window (similar to V3 and V4) that allows Javascript to be added to the entity.
Form Scripting in CRM 2011 - 1
Customising Form Events for the Account Entity in CRM 2011
(3) From here we can either attach a Web Resource containing Javascript functions to the Account entity, or create a new Web Resource from scratch.
Form Scripting in 2011 - 2
Creating a new Javascript Web Resource from the Account Form that can then be used to hold Script Functions for events in the Account Form to invoke
(4) Typically here we would upload an existing JS file to import developed Javascript into the entity’s events – however we can also use the Text Editor button to amend or insert new Javascript directly into the Web Resource. This mimics the current method in CRM 3 and 4.
Form Scripting in CRM 2011 - 3
Directly developing the Javascript function code behind the Web Resource
(5) With the function developed within the Web Resource, and the Web Resource saved and attached to the entity within Form Properties – we can then attach the function to a particular event within the entity.
Form Scripting in CRM 2011 - 4
Attaching the helloWorld Javascript function within the Web Resource to the Account's onLoad Event with parameter
(6) This then gives us the Form Properties of the entity listing the Web Resource(s) in use with the entity, and the events that are invoking those functions:
Form Scripting in CRM 2011 - 5
The Form Properties for the Account entity listing the newly created Web Resource and Events
(7) With those steps done, we can preview the altered Account Form with the events added to see how the Web Resource script affects the running of the Account Form.
Hello World Alert
Resulting simple Hello World pop-up box alert on load of the Account Form
This gives us a simple piece of Javascript injected into CRM 2011 via a new Web Resource, and this concept of the Web Resource illustrates the change from CRM 4 in that to affect this change both the Account Form and the Web Resource must be published as two separate components before the end result will be affected to the users of CRM. In this, we can publish out code changes via the Web Resource without changing the Account Form and vice versa.
As well as the fact that we could publish this helloWorld function out to other events in CRM (such as field onChange events or other entity’s onLoad events) by simply invoking the same function and so can avoid duplicating the actual script, as we would have had to in CRM 3 or 4.
From a development management perspective, this means we can then say goodbye to managing Javascript files for each MSCRM Event in the fashion of the Visual Studio below and instead manage files of Javascript Functions that can be invoked against a variety of MSCRM Events.
Visual Studio Management of Javascript code for CRM 4 Project
Using Visual Studio to manage the Javascript for a CRM 4 Project where the Javascript code files are tied directly to MSCRM Events
Which gives us a much more structured method of managing our script files that separates out Entity Customisation from the underlying Script Functions – even if at the cost of getting accustomed to the change and appreciating the slight rise in complexity.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Free Samples By Mail