Reputation: 18895
I've written this common function to basically clone the attributes on a form, and pass them into itself...
/*
Opens a new window, copying the current page, and loading the new item with the current values
* Sample call *
var url = "main.aspx?etn=task&pagetype=entityrecord";
var features = 'location=no,status=yes,scrollbars=no,menubar=no,toolbar=no,width=900,height=600';
CommonLib.openClone(url, '_blank', features, Xrm.Page.getAttribute(null));
*/
openClone: function (url, windowName, features, attributes) {
var qsParams = "";
var qs;
for (var i = 0; i < attributes.length; i++) {
qs = CommonLib.getExtraQS(attributes[i]);
if (qs.length > 0) {
qsParams += qs + "&";
}
} //end for
// Remove extra &
qsParams = qsParams.substring(0, qsParams.length - 1);
window.open("/" + Xrm.Page.context.getOrgUniqueName() + "/" + url + "&extraqs=" + encodeURIComponent(qsParams), windowName, features, false);
},
/*
returns the extraqs value for the attribute, non-encodURIComponent-ed
*/
getExtraQS: function (attribute) {
var extraQS = "";
if (attribute != null && attribute.getValue() != null) {
// Set name value based on type and id
switch (attribute.getAttributeType()) {
case "lookup":
var value = attribute.getValue();
var name = attribute.getName();
if (value != null && value.length > 0) {
value = value[0];
extraQS = name + "=" + value.id + "&" + name + "name=" + value.name;
switch(value.typename){
case 'account':
case 'contact':
case 'systemuser':
case 'team':
extraQS += "&" + name + "type=" + value.typename;
break;
}
}
break;
case "datetime":
extraQS = attribute.getName() + "=" + CommonLib.getCRMDateFormat(attribute.getValue());
break;
default:
extraQS = attribute.getName() + "=" + attribute.getValue();
break;
}
}
return extraQS;
}
Everything works fine unless I try to pass an attribute of type account
. I get the standard "Error. An error has occurred." If I skip the second switch statement, then I don't get a CRM Sever error, but a CRM javascript error attempting to deserialize the object because it doesn't have a type set, which results in a null pointer error.
Any ideas how to get this to work?
Edit: Turning on CRM server trace logging results in this exception which lists the regardingobjectidtype as an invalid parameter, even though it's exactly what the SDK says to use (http://msdn.microsoft.com/en-us/library/gg334375.aspx), and if I pass everything but that parameter, I get a javascript exception in the CRM javascript because the typename is null.
[2011-11-04 08:27:53.961] Process: w3wp |Organization:306a6cd8-f599-df11-b324-005056bb527b |Thread: 14 |Category: Application |User: 00000000-0000-0000-0000-000000000000 |Level: Error | ErrorInformation.LogError
at ErrorInformation.LogError()
at ErrorInformation..ctor(Exception exception, Uri requestUrl, Boolean logError)
at MainApplication.Application_Error(Object sender, EventArgs eventArguments)
at EventHandler.Invoke(Object sender, EventArgs e)
at HttpApplication.RaiseOnError()
at ApplicationStepManager.ResumeSteps(Exception error)
at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
>MSCRM Error Report:
--------------------------------------------------------------------------------------------------------
Error: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Error Message: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Error Details: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source File: Not available
Line Number: Not available
Request URL: http://dev-crmapp03.abc.com/TestOrg/userdefined/edit.aspx?actualdurationminutes=1&etc=4212&abc_category=9&abc_contactmade=false&abc_pointofcontactid=%7b7E599729-1923-E011-858E-005056BB527B%7d&abc_pointofcontactidname=Human%20Resources&abc_result=11&ownerid=%7bCAA79C99-0E9C-DF11-9D85-005056BB728E%7d&owneridname=Rachel%20Richardson&owneridtype=systemuser&pagemode=iframe®ardingobjectid=%7b58949706-1923-E011-858E-005056BB527B%7d®ardingobjectidname=Cold%20Emails%20-%20016®ardingobjectidtype=account&sitemappath=Workplace%7cMyWork%7cnav_dashboards&subject=%2a%20Security%20Alarm%20Installer%20%2f%20Technician%20%2a%20%28St.Louis%29
Stack Trace Info: [InvalidOperationException: CRM Parameter Filter - Invalid parameter 'regardingobjectidtype=account' in Request.QueryString on page /TestOrg/userdefined/edit.aspx
The raw request was 'GET /TestOrg/userdefined/edit.aspx?actualdurationminutes=1&etc=4212&abc_category=9&abc_contactmade=false&abc_pointofcontactid=%7b7E599729-1923-E011-858E-005056BB527B%7d&abc_pointofcontactidname=Human%20Resources&abc_result=11&ownerid=%7bCAA79C99-0E9C-DF11-9D85-005056BB728E%7d&owneridname=Rachel%20Richardson&owneridtype=systemuser&pagemode=iframe®ardingobjectid=%7b58949706-1923-E011-858E-005056BB527B%7d®ardingobjectidname=Cold%20Emails%20-%20016®ardingobjectidtype=account&sitemappath=Workplace%7cMyWork%7cnav_dashboards&subject=%2a%20Security%20Alarm%20Installer%20%2f%20Technician%20%2a%20%28St.Louis%29' called from http://dev-crmapp03.abc.com/TestOrg/main.aspx?etn=task&pagetype=entityrecord&extraqs=subject%3D*%20Security%20Alarm%20Installer%20%2F%20Technician%20*%20(St.Louis)%26abc_category%3D9%26regardingobjectid%3D%7B58949706-1923-E011-858E-005056BB527B%7D%26regardingobjectidname%3DCold%20Emails%20-%20016%26regardingobjectidtype%3Daccount%26abc_pointofcontactid%3D%7B7E599729-1923-E011-858E-005056BB527B%7D%26abc_pointofcontactidname%3DHuman%20Resources%26ownerid%3D%7BCAA79C99-0E9C-DF11-9D85-005056BB728E%7D%26owneridname%3DRachel%20Richardson%26owneridtype%3Dsystemuser%26abc_contactmade%3Dfalse%26abc_result%3D11%26actualdurationminutes%3D1.]
at Microsoft.Crm.Application.ParameterFilter.ValidateParameter(HttpRequest request, ArrayList parameterCollection, String key, String value, ParameterSources source, EntityType pageEntityType, FormAdditionalAllowedParameters additionalAllowedParameters)
at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, Boolean alwaysEnableParameterChecking, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp)
at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp)
at Microsoft.Crm.Application.Controls.AppPage.ValidatePageParameters()
at Microsoft.Crm.Application.Controls.PageManager.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Upvotes: 0
Views: 3202
Reputation: 18895
Ok, so I must be retarted or something... Looks like my lookup was a regarding lookup, not a customer lookup and according to the SDK link I've referenced in the question, CRM doesn't support setting this value through the extraqs.
See here for a more detailed answer: CRM 2011: Populating email entity form fields with URL parameter
Upvotes: 2