Custom entity asp page document drop redirect

I have a custom entity, called LeadDB, which is navigated to by means of a find screen. I have added a library and the library page includes the document drop.

The LeadDB may or may not be linked to a lead as its parent. Therefore I have the document linking to the lead as well if it exists. This all works perfectly, however I would like to land on the find screen from which I started after dropping the document. At present it is landing on the LeadDB, however it is not necessarily the one to which I have just attached the last document. It seems to keep going back to the same record.

Which part of the code do I need to change to achieve this? I am navigating from finding the record:

idmsql-02/.../LeadDBFind.asp

After which I open the library list and drop a document - Here is my library page:

<!-- #include file ="..\crmwizard.js" -->


<%


var sURL=
new String(Request.ServerVariables("URL")() + "?" + Request.QueryString );


Container=eWare.GetBlock(
"container");


List=eWare.GetBlock(
"LibraryList");

List.prevURL=sURL;


var Id =
new String(Request.Querystring("ledb_LeadDBID"));








if

(Id.toString() == "undefined") {

Id =
new String(Request.Querystring("Key58"));

}


var myLead = CRM.FindRecord(
"Leaddb","Ledb_leaddbid = "+Id);


/*

var myLead = CRM.CreateQueryObj(
"Select ledb_leadid from leaddb where ledb_leaddbid = "+Id);


myLead.SelectSql();


var myOppo = CRM.CreateQueryObj(
"Select ledb_Oppoid from leaddb where ledb_leaddbid = "+Id);


myOppo.SelectSql();


if

(myLead == null)

{

myComp = CRM.CreateQueryObj(
"Select oppo_primarycompanyid from opportunity where oppo_opportunityid = "+myOppo);


myComp.SelectSql();


}

else

{

myComp = CRM.CreateQueryObj(
"Select oppo_primarycompanyid from opportunity where oppo_leadid = "+myLead);


myComp.SelectSql();

}


*/

eWare.SetContext(
"LeadDB", Id);


////////////////////////////////////////////////////

/// Add Document Drop Object

////////////////////////////////////////////////////


//
Get SysParam Info

var HTTPDocStoreRecord = CRM.FindRecord(
"custom_sysparams","parm_name='HTTPDocStore'");

var PluginCodeBaseRecord = CRM.FindRecord(
"custom_sysparams","parm_name='PluginCodeBase'");


//Create Content Block
to Hold Object

var strPlugin =
"<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD>";

strPlugin +=
'<OBJECT align=center classid=clsid:3DFD2B52-C6E9-11D4-8226-005004F658FC ';

strPlugin +=
'CODEBASE="';

strPlugin +=PluginCodeBaseRecord.parm_value;

strPlugin +=
'" height=32 width=32 >';


strPlugin +=
'<PARAM NAME="PluginAction" VALUE="&quot;'

strPlugin +=
'Action=';

strPlugin +=
'DragNDrop';


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'LogonId=';

strPlugin +=CRM.GetContextInfo(
'user','user_logon');


//Action 343
is the System Action code for the librarylist.

//CRM.URL(343) works fine
for a page in the primary context of a system entity such as company.

//
In a page for a custom entity e.g. Project, you need to switch the context back to a system entity e.g. Company

//You can include all the Key Values you need
in the URL

strPlugin +=
'&quot;,&quot;';

strPlugin +=
'nextUrl=';

//strPlugin +=CRM.URL(343);

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


//
Set the context of where you need to be following the upload

strPlugin +=
'&quot;,&quot;';

strPlugin +=
'failUrl=';

strPlugin +=CRM.URL(343);


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'Alias=';

strPlugin +=HTTPDocStoreRecord.parm_value;


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'Host=';

strPlugin +=
'http://'+Request.ServerVariables('HTTP_Host');


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'DocLibPath=';

strPlugin +=
'/';


strPlugin +=
'&quot;, &quot;';

strPlugin +=
'notSavedUrl=';

strPlugin +=CRM.URL(343);


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'SelectFile=';

//strPlugin +=
'Select a File'

strPlugin +=CRM.GetTrans(
"Plugin","SelectAFile");


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'PasteFromClipboard=';

strPlugin +=CRM.GetTrans(
"Plugin","PasteFromClipBoard");


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'GeneralPluginError=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","GeneralPluginError");


strPlugin +=
'&quot;,&quot;'

strPlugin +=
'ContactPluginAdministrator=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","ContactPluginAdministrator");


strPlugin +=
'&quot;,&quot;'

strPlugin +=
'PluginFunctionError=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","PluginFunctionError");


strPlugin +=
'&quot;,&quot;'

strPlugin +=
'OutlookPluginNotInstalled=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","OutlookPluginNotInstalled");


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'PluginFileZeroinSize=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","PluginFileZeroinSize");


strPlugin +=
'&quot;,&quot;';

strPlugin +=
'PluginFileNotSaved=';

strPlugin +=CRM.GetTrans(
"DocumentPluginErrors","PluginFileNotSaved");


strPlugin +=
'&quot;">';

strPlugin +=
'</OBJECT>';

strPlugin +=
"</TD><TD>&nbsp;</TD><TD><span class="ButtonItem">"+CRM.GetTrans('Button','DocumentDrop')+"</span></TR></TABLE>";

//strPlugin +=
'<span>'+CRM.GetTrans('Button','DocumentDrop')+'</span>';


////////////////////////////////////////////////////

///
End Document Drop Object

////////////////////////////////////////////////////




Container.AddBlock(List);

Container.AddButton(eWare.Button(
"New", "new.gif", eWare.URL(343)+"&Key-1="+iKey_CustomEntity+"&PrevCustomURL="+List.prevURL+"&E=LeadDB"));

Container.AddButton(strPlugin);

Container.DisplayButton(1)=
false;


if

( Id != '')

{

eWare.AddContent(Container.Execute(
"Libr_LeadDBId="+Id));

}


eWare.GetCustomEntityTopFrame(
"LeadDB");

Response.Write(eWare.GetPage());


%>