Serialisation error when creating Quote Detail

Aug 22, 2012 at 8:31 AM

 

I'm trying to create quote detail like so, but it fails with a following error.
Looks like it does ot like 'quantity' attribute, but I'm not sure.
Please, help.

var quoteEntityType = 'quotedetail';
quoteDetailEntity = new XrmServiceToolkit.Soap.BusinessEntity(quoteEntityType);
quoteDetailEntity.attributes['quoteid'] = {
    id : Xrm.Page.data.entity.getId(),
    logicalName : 'quote',
    type : 'EntityReference'
};
quoteDetailEntity.attributes['uomid'] = {
    //id : Common.DefaultUomId,
    id : '{DB901D3B-6F88-E111-9D63-000C29A9E600}',
    logicalName : 'uom',
    type : 'EntityReference'
};
quoteDetailEntity.attributes['productid'] = {
    id : Xrm.Page.getAttribute('its_productid').getValue()[0].id,
    logicalName : 'product',
    type : 'EntityReference'
};
quoteDetailEntity.attributes['priceperunit'] = {
    type : 'Money',
    value : Xrm.Page.getAttribute('its_priceperunit').getValue()
};
quoteDetailEntity.attributes['its_outgoingpriceperunit'] = {
    type : 'Money',
    value : Xrm.Page.getAttribute('its_outgoingpriceperunit').getValue()
};
quoteDetailEntity.attributes['quantity'] = {
    type : 'number',
    value : 2.0
};

XrmServiceToolkit.Soap.Create(quoteDetailEntity, null);

 

 

Exception:

- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
- <s:Body>
- <s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
<faultstring xml:lang="uk-UA">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'Error in line 1 position 1563. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/2003/10/Serialization/:int'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'int' and namespace 'http://schemas.microsoft.com/2003/10/Serialization/'.'. Please see InnerException for more details.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>

Coordinator
Aug 22, 2012 at 12:34 PM

Hi.

Only specific fields needs type assigned. Common types like string, int do not require a type when assigned. Give it a try and let me know

quoteDetailEntity.attributes['quantity'] = 2;

Jaimie

Aug 22, 2012 at 2:09 PM

Sorry, but this way it gets serialised as `object` and fails insertion. See this bit of code in businessEntity.serialize:

switch (sType) {
//...
    default:
        value = (attribute.hasOwnProperty("value")) ? attribute["value"] : attribute;
        encodedValue = encodeValue(value);
        sType = (typeof value === "object" && value.getTime) ? "dateTime" : sType;
        xml.push('<b:value i:type="c:', sType, '" xmlns:c="http://www.w3.org/2001/XMLSchema">', encodedValue, '</b:value>');
        break;

Coordinator
Aug 23, 2012 at 9:53 AM

Hi.

The problem was caused by a wrong xmlns for the logic to handle number type in JavaScript.

you could try to use this code to overcome the issue.

quoteDetailEntity.attributes['quantity'] = {
    type : 'int',
    value : 2
};

Let me know

Jaimie

 

 

Sep 30, 2012 at 6:43 AM
Edited Sep 30, 2012 at 6:45 AM

I built a clone record function using the SOAP create method and integers were failing, so I use the following:

 

case "integer":
                    if (attribute.getValue() != null) {
                        newRecord.attributes[attribute.getName()] = { value: attribute.getValue(), type: "int" };
                    }
                    break;
case "money":
                    if (attribute.getValue() != null) {
                        newRecord.attributes[attribute.getName()] = { value: attribute.getValue(), type: "Money" };
                    }
                    break;
case "optionset":
                    if (attribute.getValue() != null) {
                        newRecord.attributes[attribute.getName()] = { value: attribute.getValue(), type: "OptionSetValue" };
                    }

 

 cheers, nzregs

Dec 6, 2012 at 12:51 PM
Hello,
What if the type is decimal ?
Coordinator
Dec 8, 2012 at 7:32 PM

Hi Fabson.

Try this code.

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

Jaimie

Jul 31, 2014 at 11:25 PM
Hello Jaimie,

I'm currently stuck in this issue of deserialization error and can't find the solution to it. I've tried a couple of tricks I've seen online even the last post you suggested in this topic but still keep getting the same message saying that the Entity Team does not map (Text below). Did you ever figure out what exactly could be causing this? I keep finding issues related to EnableProxyTypes, etc. related to plugins but nothing with this error on JS other than this and a couple others. Would there be something internally in CRM that I need to change to get this to work. I did update this organization from UR 11 to 12 after testing the 11 thoroughly. Any ideas?
Microsoft Dynamics CRM Error Report Contents

<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'Error in line 1 position 883. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://www.w3.org/2001/XMLSchema:team'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'team' and namespace 'http://www.w3.org/2001/XMLSchema'.'.  Please see InnerException for more details.</Message>
   <Line>1622</Line>
   <URL>/%7B635424450250003236%7D/WebResources/rst_XrmServiceToolkit</URL>
   <PageURL>/userdefined/edit.aspx?etc=112&id=%7b12CE178D-C54E-C3C7-91E3-55DEC0E8FC20%7d&pagemode=iframe</PageURL>
   <Function>anonymousheformatterthrewanexceptionwhiletryingtodeserializethemessage:Therewasanerrorwhiletryingtodeserializeparameterhttp://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.TheInnerExceptionmessagewas'Errorinline1position883.Element'http://schem</Function>
   <CallStack>
    <Function>anonymousheformatterthrewanexceptionwhiletryingtodeserializethemessage:Therewasanerrorwhiletryingtodeserializeparameterhttp://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.TheInnerExceptionmessagewas'Errorinline1position883.Element'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value'containsdatafromatypethatmapstothename'http://www.w3.org/2001/XMLSchema:team'.Thedeserializerhasnoknowledgeofanytypethatmapstothisname.ConsiderchangingtheimplementationoftheResolveNamemethodonyourDataContractResolvertoreturnanon-nullvalueforname'team'andnamespace'http://www.w3.org/2001/XMLSchema'.'.PleaseseeInnerExceptionformoredetails.</Function>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)</BrowserUserAgent>
   <BrowserLanguage>en-US</BrowserLanguage>
   <SystemLanguage>en-US</SystemLanguage>
   <UserLanguage>en-US</UserLanguage>
   <ScreenResolution>1920x1080</ScreenResolution>
   <ClientName>Web</ClientName>
   <ClientTime>2014-07-31T19:22:39</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>1033</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>1033</UserCulture>
    <OrgID>{FFAE8A98-B228-4617-981B-4A9902535006}</OrgID>
    <UserID>{0A51B463-DF74-E011-81B3-00155D7A7A17}</UserID>
    <CRMVersion>5.0.9690.3236</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>

Coordinator
Aug 5, 2014 at 4:32 PM
Hi HectorTosado.

A possible reason is that the query passed is not encoded properly, so CRM will not be able to read it.

It will be great if you can provide more details about the problem. How did you write your code and how it was called.

Kind Regards,
Jaimie
Aug 20, 2014 at 5:13 AM
Hello Jaimieji,

I did this stackoverflow question to explain my issue.
StackOverFlow Question

Been at it for awhile now and I believe the issue lies with how I'm setting the value in Javascript and how XrmServiceToolkit is serializing it so CRM can understand it. At the moment I've been presented with 2 issues:

First issue was when assigning a team to an owner field, using CRMServiceToolkit using
var oOwnerObject = new Object();
oOwnerObject.type = oTempSA.attributes["ownerid"].entityType;
oOwnerObject.value = oTempSA.attributes["ownerid"].id;
oSA.attributes["ownerid"] = oOwnerObject;
Worked like a charm. But when upgrading to UR 12 and thus having to change to XrmServiceToolkit I had to change it to
oSA.attributes["ownerid"] = {
    id : oTempSA.attributes["ownerid"].id,
    logicalName : oTempSA.attributes["ownerid"].entityType,
    type : 'EntityReference'
};
I still haven't been able to test it completely since I still have other issues with the serialization but it doesn't display the error related to Team entity not mapping.
oTempSA is just another SA

Second issue is with Activity Party's. Service Activity entity has a required field of equipment and the way I set this in CRMServiceToolkit was
        var oActivityParty = new Object();
        oActivityParty.partyid = new Object();
        oActivityParty.partyid.type = "equipment";
        //oActivityParty.partyid.typecode = "4000";        
        oActivityParty.partyid.value = szDefaultResourceFetchResults[0].getValue('equipmentid');

        var oActivityPartyList = new Array();
        oActivityPartyList[0] = new Object();
        oActivityPartyList[0].activityparty = oActivityParty;

        oSA.attributes["resources"] = oActivityPartyList;
Where a member of my team had to go to the toolkit and change the serialization method and add a if parameter to call a special method in case an Activity Party was being set in the request.
    _businessEntity.prototype.serialize = function () {
        var xml = '<entity xsi:type="' + this.name + '">';
        for (var attributeName in this.attributes) {
            var attribute = this.attributes[attributeName];

            var value;
            if (attribute == null) {
                value = "";
            }
            else {
                value = attribute.value || attribute;
            }

            xml +=
                '<' + attributeName + (!attribute ? '' : (!attribute.type ? '' : ' type="' + CrmEncodeDecode.CrmXmlEncode(attribute.type) + '"')) + '>' +
                    ((typeof value === "object" && value.getTime)
                        ? _encodeDate(value)
                         : (typeof value === "object" && typeof value[0] === "object" && typeof value[0].activityparty === "object")
                            ? this.serializePartyList(value)
                            : CrmEncodeDecode.CrmXmlEncode(value)) +
                '</' + attributeName + '>';
        }

        xml += '</entity>';
        return xml;
    };

    _businessEntity.prototype.serializePartyList = function (partylist) {

        var xml = '';
        for (i = 0; i < partylist.length; i++) {
            xml += '<activityparty>';
            xml += '<partyobjecttypecode>' + partylist[i].activityparty.partyid.type + '</partyobjecttypecode>';
            xml += '<partyid>' + CrmEncodeDecode.CrmXmlEncode(partylist[i].activityparty.partyid.value) + '</partyid>';
            xml += '</activityparty>';
        }
        return xml;
    };
This issue I'm still trying to solve on how to do it on XrmServiceToolkit as I'm getting the following error when I try and utilize this method:
Microsoft Dynamics CRM Error Report Contents
<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'There was an error deserializing the object of type Microsoft.Xrm.Sdk.Entity. The token '"' was expected but found '<'. Line 1, position 4137.'.  Please see InnerException for more details.</Message>
   <Line>1747</Line>
   <URL>/%7B635440774190003236%7D/WebResources/rst_XrmServiceToolkit</URL>
   <PageURL>/userdefined/edit.aspx?_gridType=112&etc=112&id=%7b95152054-55CC-2080-4993-4141B591C701%7d&pagemode=iframe&rskey=878223951</PageURL>
   <Function>anonymousheformatterthrewanexceptionwhiletryingtodeserializethemessage:Therewasanerrorwhiletryingtodeserializeparameterhttp://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.TheInnerExceptionmessagewas'TherewasanerrordeserializingtheobjectoftypeM</Function>
   <CallStack>
    <Function>anonymousheformatterthrewanexceptionwhiletryingtodeserializethemessage:Therewasanerrorwhiletryingtodeserializeparameterhttp://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.TheInnerExceptionmessagewas'TherewasanerrordeserializingtheobjectoftypeMicrosoft.Xrm.Sdk.Entity.Thetoken'"'wasexpectedbutfound'<'.Line1,position4137.'.PleaseseeInnerExceptionformoredetails.</Function>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729)</BrowserUserAgent>
   <BrowserLanguage>en-US</BrowserLanguage>
   <SystemLanguage>en-US</SystemLanguage>
   <UserLanguage>en-US</UserLanguage>
   <ScreenResolution>1440x900</ScreenResolution>
   <ClientName>Web</ClientName>
   <ClientTime>2014-08-20T00:53:24</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>1033</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>1033</UserCulture>
    <OrgID>{1DE5A3AE-575F-4384-923E-D13D77A1A66F}</OrgID>
    <UserID>{287532DE-724C-E311-90C1-54624E0DB60E}</UserID>
    <CRMVersion>5.0.9690.3236</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>

Aug 21, 2014 at 4:17 PM
Hey Jaimie,

Got it working correctly by defining an acitivty party like so in JS and then XrmServiceToolkit wouldcorrectly serialize it:
    //Create new Array with EntityCollection Type
    var partylist = new Array();
    partylist.type = 'EntityCollection';
    //Create object in array to define what in the partylist. 
    partylist[0] = new Object();
    partylist[0].id = szDefaultResourceFetchResults[0].getValue('equipmentid'); //Guid (i.e., Guid of User or Contact etc)
    partylist[0].name = szDefaultResourceFetchResults[0].getValue('name'); //Name (i.e., Name of User or Contact etc)
    partylist[0].logicalName = "equipment"; //entity schema name of account or contact
    //Assign Value
    oSA.attributes["resources"] = partylist;