Monday, December 17, 2007

Automatically complete a task via a callout

Code:

public void CompleteTask(Guid taskId)
{
SetStateTaskRequest tr = new SetStateTaskRequest();

tr.EntityId = taskId;
tr.TaskState = new TaskState();
tr.TaskState = TaskState.Completed;
tr.TaskStatus = -1 ; // Set this field to -1 to have the platform set the appropriate value

service.Execute(tr);
}


Unfortunately for some unknown reason; completing the task using the above code will cause the workflow (a Sales Process workflow was tested) to end.

Wednesday, December 12, 2007

Prevent a form from being saved

Javascript - OnSaved() event



Actually it's:

event.returnValue = false;
return false;

What aborts the Save operation.
.

Thursday, November 29, 2007

Webservice development and live server

When developing a webservice





















And when deploying to production server

using WindowsApplication3.MossCrm;

string mossUserName = ConfigurationSettings.AppSettings["UserName"].ToString();
string mossPassword = ConfigurationSettings.AppSettings["Password"].ToString();
string mossDomain = ConfigurationSettings.AppSettings["Domain"].ToString();
string mossWebServiceUrl = ConfigurationSettings.AppSettings["WebServiceUrl"].ToString();

MossCrm.Service service = new MossCrm.Service();

service.Credentials = new System.Net.NetworkCredential(mossUserName, mossPassword, mossDomain);
service.Url = mossWebServiceUrl;


App.config



.

Wednesday, November 28, 2007

How to write to the Event Viewer

from http://support.microsoft.com/kb/307024

using System.Diagnostics;

...
WriteToEventViewer("MOSS-CRM Webservice", "Application", "User provided is invalid");

...

private void WriteToEventViewer(string sSource, string sLog, string sEvent)
{
if (!EventLog.SourceExists(sSource))

EventLog.CreateEventSource(sSource, sLog);

EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning, 234);
}

Also:

System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application");

eventLog.Source = "Rtws";

eventLog.WriteEntry(ex.ToString(), System.Diagnostics.EventLogEntryType.Error);




end

Variables in web.config

Web.config

< ?xml version="1.0"?>
...
< appSettings>
< add key="SiteUrl" value="http://dev.site.com/sales"/ >
< add key="ListName" value="Shared Documents"/ >
< /appSettings> 
...
< /system.web >
< /configuration >

Some.aspx.cs

using System.Configuration;

string siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
string listName = ConfigurationManager.AppSettings["ListName"];

Tuesday, November 27, 2007

A callout is a Class Library

A callout is an assembly of type Class Library.

Thursday, November 22, 2007

Adding a folder to a Sharepoint list

From http://blogs.msdn.com/adamhems/archive/2007/08/30/progammatically-adding-folders-to-a-sharepoint-list.aspx

string siteUrl = "http://sample.development.com/sales/prospects";

string listName = "Shared Documents";

SPSite siteCollection = new SPSite(siteUrl);
SPWeb site = siteCollection.OpenWeb();
SPList list = site.Lists[listName];

SPListItem folder = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null);

if (folder != null)
{
folder["Name"] = "NameofFolder";
folder.Update();
}

Wednesday, November 21, 2007

Differentiate between contact and account (customerid)

if(opportunity.customerid.type == EntityName.account.ToString())
{
account account = (account)service.Retrieve(EntityName.account.ToString(), opportunity.customerid.Value, new AllColumns());

if(account.revenue != null)
{
opportunity.new_accountvalue = new CrmMoney();
opportunity.new_accountvalue.Value = account.revenue.Value;
}
}
else if(opportunity.customerid.type == EntityName.contact.ToString())
{
contact contact = (contact)service.Retrieve(EntityName.contact.ToString(), opportunity.customerid.Value, new AllColumns());

if(contact.creditlimit != null)
{
opportunity.new_accountvalue = new CrmMoney();
opportunity.new_accountvalue.Value = contact.creditlimit.Value;
}
}

service.Update(opportunity);

Thursday, November 8, 2007

Another Null Reference Exception CRM

Task post create event:

public override void PostCreate(...)
{
Guid opportunityId = task.regardingobjectid.Value;
this.opportunity = (opportunity)service.Retrieve(EntityName.opportunity.ToString(), opportunityId, new AllColumns());

opportunity.new_textfield = "hello world"; // throws a NullReferenceException

string newtext = "hello world";
opportunity.new_textfield = newtext; // works fine
}

Monday, November 5, 2007

CRM Lists links

From
http://sharepointsix.blogspot.com/2007/06/microsoft-crm-30-integrating-crm-into.html

DataGrid Lists
Accounts - http://crm/_root/homepage.aspx?etc=1
Contacts - http://crm/_root/homepage.aspx?etc=2
Opportunities - http://crm/_root/homepage.aspx?etc=3
Leads - http://crm/_root/homepage.aspx?etc=4
Marketing List - http://crm/_root/homepage.aspx?etc=4300
Reports - http://crm/CRMReports/home_reports.aspx
Activities - http://crm/workplace/home_activities.aspx
Calendar - http://crm/workplace/home_calendar.aspx
Articles - http://crm/workplace/home_answers.aspx
Queues - http://crm/workplace/home_workplace.aspx
Competitors - http://crm/_root/homepage.aspx?etc=123
Products - http://crm/_root/homepage.aspx?etc=1024
Sales Literature - http://crm/_root/homepage.aspx?etc=1038
Quotes - http://crm/_root/homepage.aspx?etc=1084
Orders - http://crm/_root/homepage.aspx?etc=1088
Invoices - http://crm/_root/homepage.aspx?etc=1090
Quick Campaigns - http://crm/MA/home_minicamps.aspx
Campaigns - http://crm/MA/home_camps.aspx
Cases - http://crm/CS/home_cases.aspx
Contracts - http://crm/_root/homepage.aspx?etc=1010
Services - http://crm/_root/homepage.aspx?etc=4001

Replace crm for crmdev.mydomain.com or something like that.

Edit:
This links apparently work for the 4.0 version of crm, for example:

Opportunities - http://crm.domain.com/Organization/_root/homepage.aspx?etc=3

Tuesday, October 30, 2007

Object reference not set to an instance of an object

When coding callouts:

string qualifiedStatus = opportunity.new_qualifiedstatus.Value.ToString();

new_qualifiedstatus is a picklist. If we haven't selected any value from that picklist we will get a null reference exception (not an empty or null string). So the right way to assign this would be:

if(opportunity.new_qualifiedstatus != null)
{
string qualifiedStatus = opportunity.new_qualifiedstatus.Value.ToString();
}

Saturday, October 27, 2007

Be a pointer my friend

Empty your memory,
with a free()….
like a pointer!
If you cast a pointer to a integer,
it becomes the integer,
if you cast a pointer to a struct,
it becomes a struct….
The pointer can crash…,
and can Overflow…
Be a pointer my friend….

Thursday, October 25, 2007

Hammer tool

Sometimes, when the only tool you have is a hammer, every problem starts to look like a nail.

Tuesday, October 23, 2007

Disable a field - CRM javascript

How to disable a field on a CRM form? A picture is worth a thousand words.