Deeply stuck trying to do something that should be simple
-
20 Mei 2008 15:24
Hello all,
I am hoping that somebody out there can help me with the following because I am not getting anywhere with it.
I am trying to display a custom treecontrol within an IFRAME on a new tab within the Customer Account Form. That isnt the problem, the tree control displays beautifully.
What I want to do is dynamically access the GUID of the customer account (using Javascript) and pass that as a variable into the following code. I want to code to check for a related database with the GUID in the name (each customer will have a mini-database, dont ask, there is a very good reason). Also, when a new database is created, I want to append the GUID number to the file name so that it can be identified by the CRM as the database belonging to that customer.
Simple huh? Nope. I'm stuck. I'm not a very good javascript developer as my language is ASP. I've been all over and I cannot find out how to do it. Perhaps someone can assist me with modifying the code below to do the job described. Oh yes, can the GUID be stripped of the curly braces?
Thanks in advance
CODE :
<!-- This is the test file to read the customer GUID from the CRM into here as a global variable and then append
the GUID to the database name so that the correct database can be identified for each customer -->
<script language="JScript" runat="server">
var Jet10 = 1
var Jet11 = 2
var Jet20 = 3
var Jet3x = 4
var Jet4x = 5var conn = Server.CreateObject("adodb.connection");
var fso = Server.CreateObject("Scripting.FileSystemObject");
var sFolder = Server.MapPath(BasePath);
var sFile = sFolder + "\\tree.mdb";
// tree.mdb exists?
if (!fso.FileExists(sFile))
{
createNewMDB(sFile, Jet4x);
// create table
var sql = "CREATE TABLE tree(id counter primary key, nodename memo, parent memo, display bit)";
conn_open();
conn.Execute(sql);
// initialize root node
sql = "insert into tree(nodename) values('root')";
conn.Execute(sql);
}
else
{
conn_open();
}fso = null; // reset fso object to null!
// create new tree.mdb
function createNewMDB(FileName, Format)
{
var catalog = Server.CreateObject("ADOX.Catalog");
catalog.Create ("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=" + Format + ";Data Source=" + FileName);
catalog = null;
}// connect tree.mdb
function conn_open(){
//var connstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" + db ;
var connstr = "provider=microsoft.jet.oledb.4.0;data source=" + sFile;
conn.Open (connstr, "", "");
}// close tree.mdb
function conn_close(){
conn.Close();
conn = null;
}
</script>
Semua Balasan
-
21 Mei 2008 7:43
Anyone?
What I really need to do is access the request object of the page to retrieve the ID?
-
21 Mei 2008 12:28
OK
Lets put this another way...
The javascript is running in an IFRAME.
I want to pass the id of the page (the customer GUID) into that javascript page to be used as a variable.
1) I can have a field on the form which is read only (untidy but do-able)
or
2) The javascript code running in the IFRAME identifies the querystring and passes this into a variable for later use. The problem is that I cannot figure out how to specify a session variable (i.e, one that perpetuates until the session is closed). What is happening at the moment is that the variable is dying when a new part of the code is initiated on another page.
I either have to have each page freshly identify the id and assign it to a variable using a function, or there is someway that I am missing to pass the value of the field on the form to the code in the IFRAME.
I cannot seem to use document.crmForm.all.<fieldname> and neither does crmForm.all.<fieldname>.value seem to work!
Please would someone have a stab at it?
-
22 Mei 2008 4:57
You can access object of the page to retrieve by using the example below (JavaScript):
Code Snippetvar ObjectId = crmForm.ObjectId;
alert(ObjectId);
var ObjectType = crmForm.ObjectTypeCode;
alert(ObjectType);
var Security = crmFormSubmit.crmFormSubmitSecurity.value;
alert(Security);
Some good CRM reference sites related to this issue you're having:
http://blogs.msdn.com/crm/archive/2007/11/16/integrating-crm-4-0-contacts-with-facebook.aspx