Monday, December 28, 2009

Object Oriented in JavaScript

Assuming you have a function on the OnLoad Event, and you want to access a variable of the function on the OnSave / ISV button of that entity, do the following

//the following method has an Object named NameObject.
//and also a local variable localName
//ON LOAD
function ObjectOrientedTest()
{
NameObject = function ()
{
this.firstName = "Geoffrey";
this.lastName = "Joe";
this.fullName = "Geoffrey Joe Ignatius";
this.systemUserId = "igeoff";
}
var localName="GI Joe";
}

//ON SAVE
function CallObjectOrientedTest()
{
//trying to access the variable in the NameObject
var nn = new NameObject();
alert(nn.firstName); //WILL SUCCEED
alert(localName); //WILL FAIL
}

Global Variables in JavaScript

Tuesday, December 22, 2009

Customizing Print Preview

http://adrian-alexan.blogspot.com/2009/12/customizing-entities-print-preview-form.html

Thursday, December 17, 2009

Automatically take the screen shot of the current page using C#

using System.Drawing;
using System.IO;
using System.Drawing.Imaging;

Bitmap bitmap = new Bitmap(128, 102);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(@"c:\temp\screenshot.bmp", ImageFormat.Bmp);

Not able to TRACK an email in OUTLOOK

What if, if the user is not able to Track an Email in MS CRM Suddenly?
Please follow the below URL for a solution.

http://support.microsoft.com/kb/933234

Untrack in MS CRM Outlook Client

The Track in CRM functionality is one of the most useful pieces of integration between Outlook and Microsoft CRM. The one drawback with this feature is that Microsoft didn't provide a way to "untrack" a record (specifically email records). Sometimes the user may have clicked "Track in CRM" on the wrong email or even more common is setting the wrong regarding record on accident.

The article in the URl depicts a method to untrack an email MS CRM.

http://blog.sonomapartners.com/2007/05/remove_crm_link.html

Wednesday, December 16, 2009

Spell Check in Dx CRM

The below URL has an add-on which can spell check on IE

You can do spell check on a field in Dx CRM

http://www.iespell.com/

How to send a file to a Default Printer

Scenario : In some cases the user might want to print all the documents attached to an entity.
Approach
1. Create an ASPX page to do the below
a. Get the EntityId
b. Select the notes for the EntityId
c. Get the document for the notes
d. Send the document to the default printer. [make sure that the default printer is set]
Code Example – Please edit the code as per the need

public partial class _Default : System.Web.UI.Page
{
CrmService service;
protected void Page_Load(object sender, EventArgs e)
{
CrmServiceInititate();
//string entityId = Request.QueryString["id"];
//[TESTING]
string entityId = "E1FEE803-1FE9-DE11-8B94-02BF92D77DD6";
ReadAnnotationsforEntity(entityId);
}

//READ THE ANNOTATIONS FOR AN ENTITY
public void ReadAnnotationsforEntity(string entityId)
{



string result = service.Fetch(fetch);

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(result);

XmlNodeList xndl = xDoc.SelectNodes("resultset/result");

string annotationId = string.Empty;
foreach (XmlNode xnd in xndl)
{
annotationId = xnd.SelectSingleNode("annotationid").InnerText;
ReadAttachedFilesinAnnotation(annotationId, entityId);
//break;
}
}

//ANNOTATION - NOTE
public void ReadAttachedFilesinAnnotation(string annotationId, string entityId)
{

//get the attached files for a note in an entity.
// Define the columns to retrieve from the annotation record.
ColumnSet cols1 = new ColumnSet();
cols1.Attributes = new string[] { "filename", "documentbody" };

// Retrieve the annotation record.
annotation annotationAttachment = (annotation)service.Retrieve(EntityName.annotation.ToString(), new Guid(annotationId), cols1);


// Download the attachment in the current execution folder.
string url = Server.MapPath(".\\Attachments");
string newPath = System.IO.Path.Combine(url, entityId);
System.IO.Directory.CreateDirectory(newPath);
url = newPath + "\\" + annotationAttachment.filename;

//using (FileStream fileStream = new FileStream(annotationAttachment.filename, FileMode.OpenOrCreate))
using (FileStream fileStream = new FileStream(url, FileMode.OpenOrCreate))
{
byte[] fileContent = new UTF8Encoding(true).GetBytes(annotationAttachment.documentbody);
fileStream.Write(fileContent, 0, fileContent.Length);
}
//SendFileDefaultPrinter(url);
}

public void SendFileDefaultPrinter(string url)
{
//THIS WILL PRINT ALL THE FORMATS
//BUT MAKE SURE THAT THE DEFAULT PRINTER IS SELECTED
Process printJob = new Process();
printJob.StartInfo.FileName = url;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "print"; //THIS SHOULD ALWAYS BE PRINT AS PRINT IS THE ACTION THAT HAS TO BE DONE NOW
printJob.Start();
}

public void CrmServiceInititate()
{
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = AuthenticationType.AD;
token.OrganizationName = <>;

//******************UAT in same domain ********************************************************************
service = new CrmService();
service.CrmAuthenticationTokenValue = token;
//service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Credentials = new System.Net.NetworkCredential(<>, <>,<>);
}
}

2. Host the above application Host the Custom Application (Ex: ISV\CHALLITS\CRMExtended\WebApplications\SendDoctoPrinter\Default.aspx)
3. Create an ISV button on the entity to call the ASPX Page [you can do this on Button URL]

ISV Button & Pass Parameters

Scenario: When I click a button on the opportunity form, a code should run behind which will generate a PDF. The fields on the opportunity should be marked on the PDF.
Approach
1. Write a custom code (ASPX,C#) with an input parameter for the opportunity id and generate a PDF.
2. Host the Custom Application (Ex: ISV\CHALLITS\CRMExtended\WebApplications\PrintPDF\default.aspx)
3. Create an ISV button as below




Expected output: When the button is clicked, the process will run behind which will generate a PDF based on the selected opportunity.

Load an external script file on the load of an entity.

Put the below code on a JS file and save it as “JoeTestScript.js” in the ("/ISV/CHALLITS/CRMExtended/Scripts/ folder.
// JScript source code
function TestScriptMethod()
{
alert(" Hi Joe you have called the external java script file");
}

function load_script (url)
{
var x = new ActiveXObject("Msxml2.XMLHTTP");
x.open('GET', url, false);
x.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
x.send('');
eval(x.responseText);
var s = x.responseText.split(/\n/);
var r = /^function\s*([a-z_]+)/i;
for (var i = 0; i < s.length; i++)
{
var m = r.exec(s[i]);
if (m != null)
window[m[1]] = eval(m[1]);
}
}

function add_script (url , load)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');

script.language = 'javascript';
script.type = 'text/javascript';
script.src = url;

if (load)
{
script.onreadystatechange = function()
{
crmOnLoadScripts();
}
}
head.appendChild(script);
}

add_script("/ISV//Scripts/opportunityproduct.js", false);
//ON SAVE
TestScriptMethod (); // please note that you have to call this on save

NOTE : Delete temporary internet files.

Thursday, December 10, 2009

Consume a web-service in a class file

You wont be able to consume a Web-Reference inside a class file in VS 2008. But still you can call the web-methods and access the entities using the following steps.

1 Open the command prompt for Visual Studio
2 Type the command wsdl /out:CrmServiceWsdl.cs
http://http://uat.ocean.sony.com.sg/SGUAT/loader.aspx?
WSDL /u:username /p:password /d:domain
Ref URl : http://msdn.microsoft.com/en-us/library/7h3ystb6(VS.71).aspx
3. Open the CrmServiceWsdl.cs int the location specified in the command prompt
4. Create a class project and add the CrmServiceWsdl.cs fiel into the project.
5. Compile and Build the project
6. The CrmServiceWsdl.dll has the web-service calls and methods whcih you can access by including the dll as a reference.

Tuesday, December 8, 2009

OR + AND combination in FETCH




The above code will search for the below condition
Last name should be “Joe”
First name can be “Geoffrey” (or)
First name can be “Lavanya”

Sunday, December 6, 2009

Multi Lookup Filter

Please follow the URL to know more about filtering in Milti Lookup

Scenario : Open a Quote record, then go to Add Existing ShippingMark, then in the LookupMulti page, only return the ShippingMark which has the same Account(new_account) with Quote's(customerid).

Microsoft CRM Support Tools Downloads

Support tools for Dx CRM can be downloaded from

http://www.box.net/shared/6oxfqi2ida

Friday, December 4, 2009

Global URL's - JavaScript

SERVER_URL: This variable stores a string that specifies the base server url - the server name along with the organization name. Example: http://servername:port/organization
USER_LANGUAGE_CODE: This variable specifies the LCID value for the language pack used by the user. For English, this would be 1033.
ORG_LANGUAGE_CODE: This variable specifies the LCID value for the organization's base language. For English, this would be 1033.
ORG_UNIQUE_NAME: This variable stores a string that specifies the current organization's name.
ORG_DATE_START_DAY: Represents the first day of the week specified for the organization (0 = Sunday, 1 = Monday, etc).
IS_LIVE: Boolean value to specify whether the deployment is a CRM Live deployment.
LOCID_ARRAY_SHORT_MONTHS: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,
LOCID_ARRAY_LONG_MONTHS: January,February,March,April,May,June,July,August,September,October,November,December
LOCID_ARRAY_SHORT_DAYS: Sun,Mon,Tue,Wed,Thu,Fri,Sat
LOCID_ARRAY_SHORTEST_DAYS: Su,Mo,Tu,We,Th,Fr,Sa
LOCID_ARRAY_LONG_DAYS: Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

Attach event to a field on crmForm

You can attach an event to any field on the crmForm using the code below.

crmForm.all.name.attachEvent('onmouseover',test);

function test(){
alert('the scripting goes on this line')
}

Thursday, December 3, 2009

Workflow can be triggerd via a custom application

I came across a requirement where there are two read only lookups. Both the lookup fields will be read only. Due to some business logic constraint the first read only lookup can be only be set. The second read only lookup should be set with a value based on the first read only lookup value.

We use a custom application to set the first read only lookup value.

Then we use a workflow to get the appropriate value for the second read only lookup value based on the first read only lookup value.

It worked fine.

Wednesday, December 2, 2009

Moving of field - Dynamically

I have used JavaScript to move the field from a section in the form to another section in the same form

//the target location - next to which field
var searchEl = document.getElementById("transactioncurrencyid_d");
//the source _c
var ele_c = document.getElementById("estimatedclosedate_d").nextSibling;
//the source _d
var ele_d = document.getElementById("opportunityratingcode_c").nextSibling;
//move the fields
searchEl.nextSibling.appendChild(ele_c);
searchEl.nextSibling.nextSibling.appendChild(ele_d);

In the above example i am moving the Rating field from the Estimated Revenue section to the Opportunity Information section - next to the Currency Field(Target Location)