CRM SDK Examples??

P

Phil Adams

Hi Peeps,
I am trying to do some custom programming for CRM, but alas i am only a
classic asp programmer.
Can someone help me by translating this into asp.net in VB instead of C#, i
can then get on as i think i am okay with the rest only not too clever with
imports etc.
This is in the CRM SDK under CRMIncident.Open Method.

Thanks In Advance
[C#]
// server should be set with the name of the platform Web server
string server = "myservername";

// virtualDirectory should be set with the name of the Microsoft CRM
// Virtual Directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "http://" + server + "/" + virtualDirectory + "/";

// BizUser proxy object
Microsoft.CRM.Proxy.BizUser bizUser = new Microsoft.CRM.Proxy.BizUser ();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = strDir + "BizUser.srf";

// CRMIncident proxy object
Microsoft.CRM.Proxy.CRMIncident incident = new
Microsoft.CRM.Proxy.CRMIncident();
incident.Credentials = System.Net.CredentialCache.DefaultCredentials;
incident.Url = strDir + "CRMIncident.srf";

// CRMAccount proxy object
Microsoft.CRM.Proxy.CRMAccount account = new Microsoft.CRM.Proxy.CRMAccount
();
account.Credentials = System.Net.CredentialCache.DefaultCredentials;
account.Url = strDir + "CRMAccount.srf";

string strErrorMsg;
try
{
Microsoft.CRM.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

// Set up the XML for a new account
// The required fields are name and ownerid
string strAccountXml = "<account>";
strAccountXml += "<name>Account Number 2</name>";
strAccountXml += "<accountnumber>A01923</accountnumber>";
strAccountXml += "<websiteurl>www.account1.com</websiteurl>";
strAccountXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strAccountXml += userAuth.UserId + "</ownerid>";
strAccountXml += "</account>";

string strAccountId = account.Create(userAuth, strAccountXml);

// Set up the XML for a new incident
string strIncidentXml = "<incident>";
strIncidentXml += "<title>incident 1</title>";
strIncidentXml += "<accountid>" + strAccountId +"</accountid>";
strIncidentXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strIncidentXml += userAuth.UserId + "</ownerid>";
strIncidentXml += "</incident>";

// Create an incident
string strIncidentId = incident.Create(userAuth, strIncidentXml);

// Now open the incident
incident.Open(userAuth, strIncidentId, -1);

}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml
+ " Source: " + err.Source );
}
catch (Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message );
}
 
M

MS News \(MS ILM\)

Few pointers

1) Remove all ; ';'

2) Change + to &

3) when declaring a variable
C#: string virtualDirectory = "mscrmservices";
VB.NET: Dim virtualDirectory as String = "mscrmservices"

4) C#: strAccountXml += "<name>Account Number 2</name>";
this means strAccountXml = strAccountXml +
"<name>Account Number 2</name>"

Phil Adams said:
Hi Peeps,
I am trying to do some custom programming for CRM, but alas i am only a
classic asp programmer.
Can someone help me by translating this into asp.net in VB instead of C#, i
can then get on as i think i am okay with the rest only not too clever with
imports etc.
This is in the CRM SDK under CRMIncident.Open Method.

Thanks In Advance
[C#]
// server should be set with the name of the platform Web server
string server = "myservername";

// virtualDirectory should be set with the name of the Microsoft CRM
// Virtual Directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "http://" + server + "/" + virtualDirectory + "/";

// BizUser proxy object
Microsoft.CRM.Proxy.BizUser bizUser = new Microsoft.CRM.Proxy.BizUser ();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = strDir + "BizUser.srf";

// CRMIncident proxy object
Microsoft.CRM.Proxy.CRMIncident incident = new
Microsoft.CRM.Proxy.CRMIncident();
incident.Credentials = System.Net.CredentialCache.DefaultCredentials;
incident.Url = strDir + "CRMIncident.srf";

// CRMAccount proxy object
Microsoft.CRM.Proxy.CRMAccount account = new Microsoft.CRM.Proxy.CRMAccount
();
account.Credentials = System.Net.CredentialCache.DefaultCredentials;
account.Url = strDir + "CRMAccount.srf";

string strErrorMsg;
try
{
Microsoft.CRM.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

// Set up the XML for a new account
// The required fields are name and ownerid
string strAccountXml = "<account>";
strAccountXml += "<name>Account Number 2</name>";
strAccountXml += "<accountnumber>A01923</accountnumber>";
strAccountXml += "<websiteurl>www.account1.com</websiteurl>";
strAccountXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strAccountXml += userAuth.UserId + "</ownerid>";
strAccountXml += "</account>";

string strAccountId = account.Create(userAuth, strAccountXml);

// Set up the XML for a new incident
string strIncidentXml = "<incident>";
strIncidentXml += "<title>incident 1</title>";
strIncidentXml += "<accountid>" + strAccountId +"</accountid>";
strIncidentXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strIncidentXml += userAuth.UserId + "</ownerid>";
strIncidentXml += "</incident>";

// Create an incident
string strIncidentId = incident.Create(userAuth, strIncidentXml);

// Now open the incident
incident.Open(userAuth, strIncidentId, -1);

}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml
+ " Source: " + err.Source );
}
catch (Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message );
}
 
M

MS News \(MS ILM\)

This is different, you have put some statics
dim strAccountId as string = "{38A03BA8-7C0B-487F-836D-9DAD2A64B0D2}"
where is it failing, what error? do you get?, did you debug

I am not familiar with this.
just a question: in the strAccountId do you have to have the '{' and '}'
 
M

MS News \(MS ILM\)

did you add the porper References and Imports
Project menu - Add References etc..
 
K

Ken Dopierala Jr.

If you are translating this into VB.Net then you don't have to worry about
numbers 2 and 4. The '+' sign works for strings in VB.Net just like it does
in C# and VB.Net also supports the += operator. If you are converting this
to a standard ASP 3.0 page then you will need to perform numbers 2 and 4.
Good luck. Ken.

MS News (MS ILM) said:
Few pointers

1) Remove all ; ';'

2) Change + to &

3) when declaring a variable
C#: string virtualDirectory = "mscrmservices";
VB.NET: Dim virtualDirectory as String = "mscrmservices"

4) C#: strAccountXml += "<name>Account Number 2</name>";
this means strAccountXml = strAccountXml +
"<name>Account Number 2</name>"

Phil Adams said:
Hi Peeps,
I am trying to do some custom programming for CRM, but alas i am
only
a
classic asp programmer.
Can someone help me by translating this into asp.net in VB instead of
C#,
i
can then get on as i think i am okay with the rest only not too clever with
imports etc.
This is in the CRM SDK under CRMIncident.Open Method.

Thanks In Advance
[C#]
// server should be set with the name of the platform Web server
string server = "myservername";

// virtualDirectory should be set with the name of the Microsoft CRM
// Virtual Directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "http://" + server + "/" + virtualDirectory + "/";

// BizUser proxy object
Microsoft.CRM.Proxy.BizUser bizUser = new Microsoft.CRM.Proxy.BizUser ();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = strDir + "BizUser.srf";

// CRMIncident proxy object
Microsoft.CRM.Proxy.CRMIncident incident = new
Microsoft.CRM.Proxy.CRMIncident();
incident.Credentials = System.Net.CredentialCache.DefaultCredentials;
incident.Url = strDir + "CRMIncident.srf";

// CRMAccount proxy object
Microsoft.CRM.Proxy.CRMAccount account = new Microsoft.CRM.Proxy.CRMAccount
();
account.Credentials = System.Net.CredentialCache.DefaultCredentials;
account.Url = strDir + "CRMAccount.srf";

string strErrorMsg;
try
{
Microsoft.CRM.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

// Set up the XML for a new account
// The required fields are name and ownerid
string strAccountXml = "<account>";
strAccountXml += "<name>Account Number 2</name>";
strAccountXml += "<accountnumber>A01923</accountnumber>";
strAccountXml += "<websiteurl>www.account1.com</websiteurl>";
strAccountXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strAccountXml += userAuth.UserId + "</ownerid>";
strAccountXml += "</account>";

string strAccountId = account.Create(userAuth, strAccountXml);

// Set up the XML for a new incident
string strIncidentXml = "<incident>";
strIncidentXml += "<title>incident 1</title>";
strIncidentXml += "<accountid>" + strAccountId +"</accountid>";
strIncidentXml += "<ownerid type=\"" +
Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString() +"\">";
strIncidentXml += userAuth.UserId + "</ownerid>";
strIncidentXml += "</incident>";

// Create an incident
string strIncidentId = incident.Create(userAuth, strIncidentXml);

// Now open the incident
incident.Open(userAuth, strIncidentId, -1);

}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml
+ " Source: " + err.Source );
}
catch (Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top