Combining CRM WebServices and ASP.NET

2 minute read time.
The links in this article have been corrected and updated.
It might seem that you can't use ASPX pages in the context of Sage CRM, but that is not the case as you can see from the simple example below.



You can create a seperate ASP.NET application and integrate it with Sage CRM, the key point here is that data access is going to be using Web Services.

An ASPX page can be called from a tabgroup or a buttongroup or indeed from an ASP page where the URL has been built using the eWare.URL("mypage.aspx") method. In all these cases the contextual information will be added to the querystring.

This will be in the form of:

?SID=197470424831114 &Key0=1 &Key1=28 &Key2=30 &T=Company

The Value keys are in a predicatable form, and the nature of the keys is discussed here:

https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/2007/07/13/key-values-in-urls.aspx

The most important of the variable name/value pairs that is included in the querystring is the SID. The SID is the session id. This should be valid whether used in ASP pages, the system pages or a webservice interaction.

There is an example of using the SID from an existing system logon here:

https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/2007/10/24/sid-and-key-grabber.aspx

The above ASPX example was a simple little project. The fields have been added to the form as below:



Once the Web Reference to the CRM Web Services has been added to the project the code that allowed me to add the company details using the Web Service API looked like this:



Code:



myCRM.SessionHeaderValue = new SessionHeader();
myCRM.SessionHeaderValue.sessionId = Request.QueryString.Get("SID");
getversionstringresult CRMVersion = myCRM.getversionstring();
//Response.Write(CRMVersion.versionstring);

String strCompanyID = Request.QueryString.Get("key1");
queryentityresult CompanyQueryResult = myCRM.queryentity(int.Parse(strCompanyID), "Company");
ewarebase CRMBase;
CRMBase = CompanyQueryResult.records;
company myCompanyRecord = (company)CRMBase;

CompanyNameData.Text = myCompanyRecord.name;
COMPSLADATA.Text = myCompanyRecord.slaid;
CompWebSiteData.Text = myCompanyRecord.website;
CompTypeData.Text = myCompanyRecord.type;



Note

In pages called from the tabgroup "User" in the My CRM area look like:

?SID=197470424831114 &Key0=4 &Key4=4 &T=User

Key4 here represents the Current Logged on user id. For example to be able to retrieve information from the UserContacts table then you would have to make sure that the table was exposed in Web Services.

For existing tables that you want to expose via the WSDL file then you will need to change the flag (bord_webservicetable) in the custom_tables meta data table. This can only be done in SQL. UserContacts is not exposed to webservices by default.

Within the SageCRM .NET API then the UserContacts table can be interacted with just like any other table.

And finally

If you are working with ASP.NET pages using this technique then be aware that if you invoke the Logout method it will log off your main CRM session as well.

Parents Comment Children
No Data