Benutzer mit den meisten Antworten
Force form save and fire client side event in javascript

Frage
-
Hello,
My task is to add a button to an entity A and onclick of it I have to open another entity B instance which requires the objectid of the entity A. so I have to force the formsave for entity A to get the objectid if theinstances is not saved.
task i have done so far
modified the ISV to create the button on entity A instance
included javascript:
if the form mode of entity A instance is update open a new instance of entity B
else if form mode of entity A instance is new then call crmform save.
now the point is i should be able to open a new instance of entity B only after the crmform save of entity A instance is successful.
any help is much appreciated.
thanks in advance.
Antworten
-
Hi,
maybe you can create a little workaround:
You add a new attribute to your entity called "firstLoad" - default value is true.
In the "onLoad"-Event you set this value to false, if the value is true and the form type is "update".
Furthermore, you create the new windows in the onLoad event: if the field value is "true" the form was object was just created and the onLoad occurs because of the reload after the save event.
I hope you understand were I am heading ;-)
Best regards,
Nils- Als Antwort markiert JuergenBeckModerator Montag, 17. Mai 2010 17:18
-
Hi,
you can post your english crm questions here: http://social.msdn.microsoft.com/Forums/en-US/crm/threads
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Als Antwort markiert JuergenBeckModerator Montag, 17. Mai 2010 17:18
Alle Antworten
-
Hi,
from what I have understood, you already pass the objectid to entity B.
Before you open the new window, you should check, if you have a valid objectid. If you don't have one, crmform save was not successful?!?!
Does it make sense?
Best regards,
Nils -
Hi Nils,
Thanks for the response. yeh i know its not saving and no valid objectid, as its
I can only pass the objectid to entity B only if entity instance A is saved (or the form mode is update), so that part is fine and works as expected.
the issue i have is when the entity A instance is not saved and still a new form. i do force the crmform save. but some how i don't get the objectid when i alert it.
Thanks in advance.
Regards, -
Hi,
I guess the objectid is not available, because the form is not reloaded when the javascript is exected. Therefore, you should try to create FetchXML Request in order to retrieve the newly created object (incl. the objectid). Then you can pass the objectid to the new form.
Cheers,
Nils -
Hi Nils,
On what basis should I do fetchXML request? there might be many users creating contacts simultaneously.
my code is something like this:
Option 1
<Entity name="contact" >
<ToolBar ValidForCreate="1" ValidForUpdate="1">
<Button Icon="/_imgs/arrow.gif" JavaScript="
var result = '';
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;if (crmForm.FormType == CRM_FORM_TYPE_CREATE)
{
result = crmForm.Save();
if (result)
{
alert('If This is an update form, the ID is ' + crmForm.ObjectId + '.');
var url = 'http://<servername>:portnumber/userdefined/edit.aspx?_CreateFromType=112&_CreateFromId='+crmForm.ObjectId + 'etc=10001#'
window.open(
url,
'_blank',
'height=500 width=700 left=100 top=100 resizable','false'
);
}
}
else
{
alert('This is an update form, the ID is ' + crmForm.ObjectId + '.');
var url = 'http://<servername>:portnumber/userdefined/edit.aspx?_CreateFromType=112&_CreateFromId='+crmForm.ObjectId + 'etc=10001#'
window.open(
url,
'_blank',
'height=500 width=700 left=100 top=100 resizable','false'
);
}"
PassParams="" >
<Titles>
<Title LCID="1033" Text="add address" />
</Titles>
<ToolTips>
<ToolTip LCID="1033" Text="add address" />
</ToolTips>
</Button>
<ToolBarSpacer />
</ToolBar >
</Entity >
Option 2
<Entity name="contact" >
<ToolBar ValidForCreate="1" ValidForUpdate="1">
<Button Icon="/_imgs/arrow.gif" Url=http://<servername>:portnumber/ISV/add
PassParams="1" WinParams="" WinMode="0">
<Titles>
<Title LCID="1033" Text="Brochure Request" />
</Titles>
<ToolTips>
<ToolTip LCID="1033" Text="Brochure Request" />
</ToolTips>
</Button>
<ToolBarSpacer />
</ToolBar >
</Entity >
and in the redirect.htm
i have <html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Redirect to add address screen</title>
<script type="text/jscript">
var crmForm = window.opener.document.crmForm;
var result = false;
result = crmForm.Save();
alert('first - ' + result);
function redirect()
{
if(result == false)
{
window.close();
}
else
{
alert('else - ' + result + ' --> ' + crmForm.ObjectId);
alert('else - customerid -- '+ crmForm.all.customerid.DataValue[0].id);
var url = "http://<servername>:potnumber/userdefined/edit.aspx?_CreateFromType=112&_CreateFromId";
var urlfull = url + "="+crmForm.ObjectId + "&etc=10001#";
alert(urlfull -- '+ urlfull);
location.href = urlfull;address/Redirect.htm}
}
</script>
</head>
<body onload="redirect()">
</body>
</html>
not sure what wrong iam doing here. But I know that the child window is opened before the parent form is saved. The contact form(parent form) is saved and the next statement is executed immediately..
Regards, -
Hi,
maybe you can create a little workaround:
You add a new attribute to your entity called "firstLoad" - default value is true.
In the "onLoad"-Event you set this value to false, if the value is true and the form type is "update".
Furthermore, you create the new windows in the onLoad event: if the field value is "true" the form was object was just created and the onLoad occurs because of the reload after the save event.
I hope you understand were I am heading ;-)
Best regards,
Nils- Als Antwort markiert JuergenBeckModerator Montag, 17. Mai 2010 17:18
-
Hi,
you can post your english crm questions here: http://social.msdn.microsoft.com/Forums/en-US/crm/threads
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Als Antwort markiert JuergenBeckModerator Montag, 17. Mai 2010 17:18