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