Answered by:
crm form scritping

Question
-
Hello,
I need to pass a value from a iframe to crmform, how to do?
I have in my iframe un textbox and a button when clic to the button i want to pass a value to my crmform.
ThanksThursday, January 26, 2012 3:20 PM
Answers
-
i resolved La demande a échoué avec l'état HTTP 401 : Unauthorized with uac i disabled.
- Marked as answer by dc74 Tuesday, March 20, 2012 3:47 PM
Friday, February 10, 2012 3:33 PM -
Hello,
i found solution, the error was in typename: "customer" this typename does not exist. I replaced by account and now it is ok.
Thanks
Best regards
- Marked as answer by dc74 Tuesday, March 20, 2012 3:46 PM
Wednesday, March 14, 2012 10:05 AM
All replies
-
Hi,
with window.parent you get the window object from the parent form. Which CRM are you using? 4.0 or 2011?
In both versions you should get the crmForm with window.parent.crmForm.
If you are working with Crm 2011 you should use window.parent.Xrm.Page .
hth & regards
Uli
Thursday, January 26, 2012 4:35 PM -
Thanks for your reply, i am using crm 4.0.
I will try.
Friday, January 27, 2012 8:46 AM -
You can get the id of the selected record in the iframe using following code:-
var bFired9 = false; function GridClickLead() { // check to see if this event has been fired already if (bFired9 == false) { // get array of selected records var frameDoc9 = document.getElementById("IFRAME_Lead").contentWindow.document; var a9 = frameDoc9.all['crmGrid'].InnerGrid.SelectedRecords; var selectedItems9 = new Array(a9.length); for (var i = 0; i < a9.length; i++) { selectedItems9[i] = a9[i][0]; } alert(selectedItems9); } else { // toggle our fired flag back } }
Based on this id you can get the values of selected record and populate it to the form. You can use either using CrmService.Retrieve method <h1> </h1>
Change iframe name according to your envoirnment
Regards Faisal- Edited by Faisal Fiaz Friday, January 27, 2012 10:38 AM
- Proposed as answer by Philippe LEAL Friday, January 27, 2012 8:00 PM
Friday, January 27, 2012 10:38 AM -
thanks i don't understand what you purpose. let me explain in my iframe i have a simple form which contains a textbox and a submit button. when i insert text and clic to the button ok i want to transmit the reply of this action on the crmform.
Normally when i clic on button. i retrieve the account which contain the number defined in the textbox like contract number. and transmit this account name on the crmform to replace customer in create new incident form.
Monday, January 30, 2012 11:13 AM -
Hi dc74,
what Faisal proposed was the other way. With his sample you can access iFrame content from your crmForm.
What you need, if I got it right, is to call a javascript function on your Crm page. This should work with my script sample. So assume you have a script defined on your crm Form like:
window.setNewCustomer = function (accountName) { //create new customer lookup value here }
then you can call your function from the iFrame with the following script:window.parent.setNewCustomer( "New Account" );
regardsUli
Monday, January 30, 2012 12:03 PM -
may i add changes on my button event code (aspx.Cs) or in crmform event?Monday, January 30, 2012 1:59 PM
-
window.parent dont work in my aspx code for iframeMonday, January 30, 2012 2:31 PM
-
The first code I posted should be added to the Crm Form.
The second part should go to the aspx Webpage in the HTML part, not in the code behind file.Monday, January 30, 2012 2:36 PM -
thanks, i'll try. i'll inform you of the followingTuesday, January 31, 2012 9:51 AM
-
You can use the IE Developer tools to debug the client side Javascript. just add a breakpoint in the js file/aspx file with js code and use the watch or locals window to determine how to get from the iFrame window object to the crm form window object. Maybe you have to use window.top.parent.
When I have time a can make a sample with your configuration (Crm Form with an embedded iFrame that opens an ASPX page). Can you please tell me how you have added the ASPX iFrame to your Crm Form? Simply added the iFrame with the Crm Formular Designer?
regards
Uli
Tuesday, January 31, 2012 10:47 AM -
thanks simple adding in crmform designer in a section. i am trying to modify incident form in creation mode.
Now i have this error La demande a échoué avec l'état HTTP 401 : Unauthorized
Tuesday, January 31, 2012 3:22 PM -
hello,
I try your solution but it is not work. I mean you don't get my real subject. I have my crmform, i integrated somes iframe. my iframe contains a textbox and a submit button. so when i insert a text in the iframe form. the submit work return a value i needed. Now i want to put this value into crmform field call customerid.
I am working with incident(case) createform.
I try to put in my aspx code of the iframe form the javascript:
<script type="text/jscript" language="jscript">
function searchaccount(lecompte)
{
var nomcompte = new Array;
if (window.parent.crmForm.all.customerid != null) {
window.parent.crmForm.all.customerid.Datavalue[0].name = lecompte;
}
else {
alert('no customer');
}
}
</script>in the codebehing(aspx.cs) of my iframe form i want to call this javascript code to change the customer id in the crmform.
I try to use RegisterStartupScript like this:
protected void searchbybtnId_Click(object sender, EventArgs e)
{
try
{
//Récupération du contrat et du compte correspondant
string lecompte = RetrieveAccount(searchbynumcontratId.Text);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "search", "searchaccount('" + lecompte + "');", false);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Message erreur : --- " + ex.ToString() + "');", false);
}
}
Friday, February 10, 2012 3:28 PM -
i resolved La demande a échoué avec l'état HTTP 401 : Unauthorized with uac i disabled.
- Marked as answer by dc74 Tuesday, March 20, 2012 3:47 PM
Friday, February 10, 2012 3:33 PM -
Hello,
Is there anybody to help me about this:
"
I try your solution but it is not work. I mean you don't get my real subject. I have my crmform, i integrated somes iframe. my iframe contains a textbox and a submit button. so when i insert a text in the iframe form. the submit work return a value i needed. Now i want to put this value into crmform field call customerid.
I am working with incident(case) createform.
I try to put in my aspx code of the iframe form the javascript:"
<script type="text/jscript" language="jscript">
function searchaccount(lecompte)
{
var nomcompte = new Array;
if (window.parent.crmForm.all.customerid != null) {
window.parent.crmForm.all.customerid.Datavalue[0].name = lecompte;
}
else {
alert('no customer');
}
}
</script>in the codebehing(aspx.cs) of my iframe form i want to call this javascript code to change the customer id in the crmform.
I try to use RegisterStartupScript like this:
protected void searchbybtnId_Click(object sender, EventArgs e)
{
try
{
//Récupération du contrat et du compte correspondant
string lecompte = RetrieveAccount(searchbynumcontratId.Text);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "search", "searchaccount('" + lecompte + "');", false);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Message erreur : --- " + ex.ToString() + "');", false);
}
}
Thanks for your help
Tuesday, February 14, 2012 1:42 PM -
Hi,
do you get any error message when executing the javascript of the function searchaccount? How is your iFrame confuguration on the Crm form?
There is a setting that prevents cross frame scripting which has to be disabled. Otherwise the scripts in the iFrame wont work.
Regards
Uli
Wednesday, February 15, 2012 9:07 AM -
hi,
try this code in your button Click function
window.parent.opener.Xrm.Page.data.entity.attributes.get("attribute Name").setValue(Value);
Anwar noori
Wednesday, February 15, 2012 9:54 AM -
Anwar,
he is working with Crm 4. there is no Xrm.Page available.
I also checked in my crm dev.env. adding an iFrame to a crm form calling a aspx page from the ISV folder. The javascript code window.parent.crmForm.all.customerid.Datavalue[0].name = "asdf" works fine when the security setting for cross frame scripting is allowed.
regards
Uli
- Edited by Ulrich Hüttinger Wednesday, February 15, 2012 12:25 PM
Wednesday, February 15, 2012 12:20 PM -
Hello,
Thanks for your replies, i have nothing. i mean my code don't work. nothing wrong. in my iframe config in crm i unchecked the checkbox : restrict script on several frames on General tab of iframe properties.
Ulrich do you talking about this?
But i had the same problem.
Monday, February 20, 2012 11:28 AM -
Hello ,
I solved partially my problem. with ScriptManager.RegisterStartupScript( not ScriptManager.RegisterClientScriptBlock) and i make mistake with window.parent.crmForm.all.customerid.Datavalue i put v unlike V in DataValue. Now in my pop up message i achieve all informations. But when i try to set
window.parent.crmForm.all.customerid.Datavalue[0].name = " test"; . it is not work because i can not take [0] because it is null. no values selected.
So how can i do this. and how can i see in my incident createform this change.
here is now my code:
client part:
<script type="text/javascript" language="javascript">
function retrievecompte(lecompte,idducompte) {window.parent.crmForm.all.customerid.DataValue = [{ id: idducompte,name: lecompte, typename : "customer"}];
window.parent.crmForm.all.customerid.ForceSubmit = true;}
</script>server part:
protected void searchbybtnId_Click(object sender, EventArgs e)
{
try
{
//Récupération du contrat et du compte correspondant
string lecompte = RetrieveAccount(searchbynumcontratId.Text);
id = RetrieveAccountid(searchbynumcontratId.Text);
ScriptManager.RegisterStartupScript(this, this.GetType(), "search", "retrievecompte('"+lecompte+"','"+id+"');", true);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Message erreur : --- " + ex.ToString() + "');", true);
}
}Thanks for help
Regards
Tuesday, February 21, 2012 10:14 AM -
Hello,
for this part :
window.parent.crmForm.all.customerid.DataValue = [{ id: idducompte,name: lecompte, typename : "customer"}];
I have an error on typename. the typename customer does not exist i'd replaced it by account and it ok know.
Thanks.
Regards
Tuesday, February 28, 2012 12:49 PM -
Hello,
i found solution, the error was in typename: "customer" this typename does not exist. I replaced by account and now it is ok.
Thanks
Best regards
- Marked as answer by dc74 Tuesday, March 20, 2012 3:46 PM
Wednesday, March 14, 2012 10:05 AM