A CurrentUser object in WebServices?

1 minute read time.

If you are working with Sage CRM's WebService Interface then you will know that the API is very much focussed on Data Access and not on the user interface or 'Meta Data'.

But I have written before about how we 'discover' information about the system even if it is not in the version of the WSDL that our application was first written against.

One recent article that discusses how to work towards grabbing the primary key information and how one table maybe releated to another can be found here. https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/2008/11/19/using-webservices-to-discover-relationship-information-about-tables.aspx

The hard truth remains that we have to code and create any user interface for the webservices oursleves. It also means that this is no concept of 'context' because we are responsible for the session and state management of our application.

There is no equivalent of CRM.GetContextInfo() to help us.

But we are of course able to use one fact above all. The Web Service Interface requires a logon to create the session we use. That session gives us access to the user and therefore we can create a CurrentUser object to give us much the same information we can use in either the .NET API (N.B. Sage CRM's API) or the internal COM API.

Have a look at this C# code. To be able to logon I must have a username and that is the key for everything else...

WebService CRM60 = new WebService();
string strUserLogon = "Admin";
string strUserPassword = "";
logonresult CRMlogon = CRM60.logon(strUserLogon, strUserPassword);
CRM60.SessionHeaderValue = new SessionHeader();
CRM60.SessionHeaderValue.sessionId = CRMlogon.sessionid;

string strSQLWhereClause = "user_logon = '" + strUserLogon + "'";
queryresult CRMQueryResult = CRM60.query(strSQLWhereClause, "Users");
ewarebase[] CRMBase = CRMQueryResult.records;
users CurrentUser = (users)CRMBase[0];

myInterfaceControl.Text = CurrentUser.firstname + " " + CurrentUser.lastname;

For other articles that discuss the Web Services please see:
https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/tags/Web+Services/default.aspx