A little while ago I wrote an article called "Adding the Document Drop Plugin into a Custom Page".   That article provided the code to include activex plugin into a custompage to allow upload of documents to the library.  The orginal article's code that the company and person records were in context.

Example Code 1

strPlugin +="/"+sInstallName+"/eware.dll/do?act=343&key0=1&key1="+CRM.GetContextInfo("company","comp_companyid")+"&key2="+CRM.GetContextInfo("company","comp_primarypersonid")+"&Mode=1&CLk=T&SID="+Request.QueryString("SID")+"&Key58="+Id;

There may well be examples when this code needs to be used in ASP pages supporting a custom entity when the company and person records are NOT in context.

In the screenshot above the system is hiding all the ‘sensitive info’ tabs of the company.  When this occurs the sensitive markers maybe a symptom of lost company context.

An ASP page can get information about a company in several ways.

1)  The company information may be in the URL

a)  Typically where you see the URL of the page containing a series of context variable like

&key0=1&key1=30&key2=28

then you can use the CRM.GetContextInfo() method.  I have discussed the GetContextInfo() method in the article "Understanding GetContextInfo()".

b) You can also read that directly using the Request.QueryString() method.

e.g.  var CompanyID = Request.QueryString("Key1");

The same technique can be used where the companyid appears like this in the URL

&key0=58&key58=6001&companyid=30

e.g. var CompanyID = Request.QueryString("companyid");

You can read more about Key Values in the article "Key Values in URLs".

2)

Where the companyid does not exist in the URL then you have to get the ID from the database.  There must be a way of relating the information on screen (or in context) with that company.

So if you are looking at a customer entity like a project and are on its summary screen, then the company information will existing in the foreign key field that links the project to the company.  This assumes that the project is the child record of the company.

So assuming that the companyid is stored in the proj_companyid field then we can get the companyid like the code below.  Compare this to Example Code 1 at the beginning of the article.

Example Code 2

var ProjectID= Request.Querystring("proj__projectid");
var ProjectRecord = CRM.FindRecord("project","proj__projectid="+ProjectID);
var CompanyID = ProjectRecord.proj__companyid;
var PersonID = ProjectRecord.proj__personid;

strPlugin +="/"+sInstallName+"/eware.dll/do?act=343&key0=1&key1="+CompanyID+"&key2="+PersonID+"&Mode=1&CLk=T&SID="+Request.QueryString("SID")+"&Key58="+Id;

Note:  Once the file is uploaded and saved then the context is moved to the parent Company record and the newly uploaded document is displayed in uder the Company screen.  This has to happen as we are hijacking the system actions and can not change them.