Thursday, December 31, 2009

MS CRM 3.0 "Expected '}'" and "Object expected" errors

Hello, there :-)

Have you ever encountered this situation? You write some decent, valid JS code, throw it inside a CRM field event box, Save & Close x2, publish, test, BAM!-error?

Well, provided your code is actually correct (no logical, typing or access errors), you should check the next thing. In CRM 3.0 at least (not having a 4.0 box around atm., feel free to test if you're kind enough) if you load a piece of code having its last line using a line comment, you're in for trouble. I was lucky to find that out while debugging a whole page and noticed that the line comment I was using was extended to the rest of the CRM JS code (due to CRM placing the CATCH(e){} part of the TRY{} block right on the same line with the last line of my code). That was causing havoc to the entire page.

So, remember this hint: never leave the last line of code having a line comment ( "//" ) or you're in for trouble :D


Friday, December 18, 2009

CRM 4.0 Server - Hardcore Installing

There are moments when installing the Microsoft CRM 4.0 Server can be a real pain, if your Organization doesn't offer you full "trust" in its AD (Active Directory). After some digging, finally found a working solution (start to end :P):

step 1: Find a nice Active Directory Admin to manually create 5 groups for you in the Organization Node, with full privileges for the username that you will install the CRM 4 Server with:

step 2: Create a custom precreateconfig.xml file that will look like this (ask the same friendly guy from first step to assist you with this):
<crmsetup><server><groups autogroupmanagementoff="true"><privusergroup>CN=PrivUserGroup,OU=Company Name,OU=Company Name,DC=<domain>,DC=<domain_extension></privusergroup> <sqlaccessgroup>CN=SQLAccessGroup,OU=Company Name,OU=Company Name, DC=<domain>,DC=<domain_extension></sqlaccessgroup> <usergroup>CN=UserGroup,OU=Company Name,OU=Company Name,DC=<domain>,DC=<domain_extension></usergroup> <reportinggroup>CN=ReportingGroup,OU=Company Name,OU=Company Name, DC=<domain>,DC=<domain_extension></reportinggroup> <privreportinggroup>CN=PrivReportingGroup,OU=Company Name,OU=Company Name, DC=<domain>,DC=<domain_extension></privreportinggroup> </groups></server></crmsetup>

step 3: Go Start > Run > cmd (Command Prompt) and type:
<Drive:>\CRM 4 Kit\Server\i386\SetupServer.exe /config <Drive:>\Path_to_your_creation\precreateconfig.xml

step 4:
Pray for no further random errors while enjoying your progress bars @ Setup Screen:

step 5: After setup is completed successfully, ask the same kind AD Admin to re-add the CRM Administrator (the one you installed with) in the PrivUserGroup (with Full Privileges). See step 1 for details...
step 6: Go http://<hostname>:<port>/ and enjoy your CRM (now you will most likely have the right to finally use the product you <paid> for :)
step 7: ???
step 8: Profit!

For a detailed article about 90% of this issue, you can study this MSDN KB article.

Also, if your setup failed and cannot be uninstalled/repaired, while experimenting OTHER ways of installing than the one described above, I recommend you study this MSDN KB article as well. You gotta try this one once if you wanna train your fingers in deleting keys in RegEdit @ light speed...

Cheers and may the patience be with you :)

Wednesday, December 16, 2009

WSDL Error: "Schema item 'element' named 'string' from namespace ''. [...]"


Have you ever encountered the following error?
"Schema item 'element' named 'string' from namespace ''. The global element '' has already been declared."

That's what I got when I update my webservice references. Totally nagging and a real pain. That error prevented me from being able to access all the custom fields I created on the CRM entities.
Silly as it might sound, the sole answer to this problem was to take a deep breath (no, no Skype chat), backup the WSDL file and perform some orcish style surgery.

My troubling line was this:
<s:element name="SecurityPrincipal" nillable="true" type="s2:SecurityPrincipal">
<s:element name="TargetFieldType" type="tns:TargetFieldType">

Make sure you have a backup to the original WSDL file, then nuke (a.k.a. "remove") the red-highlighted line and save the changes to the WSDL file (in my case, it was the WSDL file corresponding to the CRM SDK service). Unless there are other errors, you will be able to build your project and your customizations will be available within Visual Studio.

Good luck and happy coding afterwards!

Wednesday, December 02, 2009

How to extract Email attachments IDs (CRM 3.0)


At some point, I was requested by a manager to extend the functionality of the email entity (multiplying the number of messages sent) and I came across the attachment side. The following function is my solution to the occurring issue:

// Author: Octavian Cucuta ( octavian.cucuta [ AT ] )

// Release: ( 2nd of December 2009 ) for MS CRM 3.0
// * Gets the IDs of the uploaded attachments, as a string constant with IDs separated by pipes '|' characters
function GetEmailAttachmentsIDs()
// Returning results as a string, but locally storing data into an array, for a more practical approach
var result = Array();
// Encasing it all within a TRY{}CATCH{} block, to prevent unwanted errors
// Get table containers
var myTables = document.getElementsByTagName("table");
// Since MS did not specify a unique ID or name for the table,
// checking which one has the correct 'oname' tag.
// Tip: on email, the table we need is the 48th
for(var i = 0; i < myTables.length; i++)
if(myTables[i].oname == "1001")
// Get attachment IDs
var index = 0;
for(var j = 0; j < myTables[i].rows.length; j++)
result[index] = "";
result[index++] = myTables[i].rows[j].oid;
// Cancelling the processing loop here
catch (err)
// In case something went wrong, instead of providing a partial set of attachments, return none
result = Array();

// Format output as a single string constant, separated by pipes
return result.join('|');

// Usage: place this function inside the needed event code body, then use the following call
var ids = GetEmailAttachmentsIDs();