Sage CRM 2017 R2: Embedding Sage CRM Screens (ASP & .NET extensions) in External Applications

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Sage CRM 2017 R2: Embedding Sage CRM Screens (ASP & .NET extensions) in External Applications

  • Comments 1
  • Likes

This article has been written for partners who need to be able to call Sage CRM screens in the context of external applications.  This is not such a strange idea as there are several partners who have created add-ons to MS Office or to other desktop products that need to reference screens and data from within Sage CRM.  If you are using a windows based application then you too may want to "pop up" a screen showing information that was derived from within Sage CRM.    

I have discussed in a previous article how PDF reports can be embedded into another system.

It isn't just system pages that can be referenced.  We can also call ASP and .NET assemblies.  But whether you are calling a system page, a NET assembly or a classic ASP page all screens in Sage CRM there are default navigational and user features present.  Below is a screen shot of the an ASP page being called in the context of the 'My CRM menu'.  The page is a simple partial rebuild of the OpportunitiesList.

This page produces this list because the page is passed details of a valid session.  This Session ID allows the CRM object to be instantiated and initialised.  The API requires a Session to be used.  This is the mechanism that ties the interface into the security policies.  And this would be very similar if we wanted to call .NET assembly.

If we were to embed this page in another application then we would also need to make sure that we did not include the 'TopContent' and other navigational features.

The URL that called this screen looks like

http://[servername]/[instancename]/CustomPages/MyOppoList.asp?SID=65906701258540&Key0=4&Key4=9&J=MyOppoList.asp&T=User

If we want to suppress the TopContent we can do so by extending the URL with an additional variable or flag.

http://[servername]/[instancename]/CustomPages/MyOppoList.asp?SID=65906701258540&Key0=4&Key4=9&J=MyOppoList.asp&T=User&popupwin=Y 

But in order for an external application to make this call to Sage CRM it must have a valid Sage CRM session ID.  This can be created by the SOAP web services.

To do this I started a Visual Studio project AND created a new Windows application.

The main items to point out are

a) The project read a Sage CRM WSDL endpoint to obtain its class and object references.

b) It is use a web browser control.

c) The user can confirm the web services URL to be used and enter their credentials.

In my example the project when run looks like this.

  

The C# code that produced the screen looks like this.

using System;
using System.Windows.Forms;
using MyOppoList2017.SageCRM;


namespace MyOppoList2017
{
public partial class Form1 : Form
{
WebService CRMService = new WebService();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
CRMService.Url = textBoxURL.Text;
}

private void button2_Click(object sender, EventArgs e)
{
//root requests to particular CRM install
//CRMService.URL = "http://servername/crminstallname/eware.dll/webservices/soap";
//If 401 Access Denied Errors occur
//CRMService.Credentials = System.Net.CredentialCache.DefaultCredentials;
logonresult CRMLogon = CRMService.logon(textBoxUsername.Text, textBoxPassword.Text);
CRMService.SessionHeaderValue = new SessionHeader();
CRMService.SessionHeaderValue.sessionId = CRMLogon.sessionid;


int eWarePos = CRMService.Url.IndexOf("eware");
string myCRMInstanceURL = CRMService.Url.Substring(0, CRMService.Url.Length - eWarePos);
string myFullURL = myCRMInstanceURL
+ "/CustomPages/MyOppoList.asp?SID="
+ CRMService.SessionHeaderValue.sessionId
+ "&Key0=4&Key4=1&Key65=395&J=MyOppoList.asp&T=User&PopUpWin=Y";

textBoxTarget.Text = myFullURL;

webBrowser1.Navigate(myFullURL);

}
}
}

This is the code for the ASP page ("MyOppoList.asp") that was called.

<!-- #include file ="sagecrm.js"-->
<!-- Typical ASP Page Structure (Try - Catch) -->
<%
var intRecordId = CRM.GetContextInfo("user","user_userid");
var myBlock = CRM.GetBlock("myoppolist");
var Arg = "oppo_assigneduserid="+intRecordId;
CRM.AddContent(myBlock.Execute(Arg));
Response.Write(CRM.GetPage());
%>

 

Comments
  • This is really cool Jeff!  Nice to know and thank you for sharing it!