Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

dynamics crm - Exception while creating Quote in CRM using GenerateQuoteFromOpportunity through javascript

Here is my code which was generated from CRMRestBuilder;

var parameters = {};
parameters.OpportunityId = "guide here..."; // I removed the guid for security purpose

var generateQuoteFromOpportunityRequest = {
    OpportunityId: parameters.OpportunityId,

    getMetadata: function() {
        return {
            boundParameter: null,
            parameterTypes: {
                "OpportunityId": {
                    "typeName": "Edm.Guid",
                    "structuralProperty": 1
                }
            },
            operationType: 0,
            operationName: "GenerateQuoteFromOpportunity"
        };
    }
};

Xrm.WebApi.online.execute(generateQuoteFromOpportunityRequest).then(
    function success(result) {
        if (result.ok) {
            var results = JSON.parse(result.responseText);
        }
    },
    function(error) {
        console.log(error.message);
    }
);

I am getting the following exception while calling;

An error occurred while validating input parameters: Microsoft.OData.ODataException: Cannot convert the literal 'undefined' to the expected type 'Edm.Guid'. ---> System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException) at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result) at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) at System.Guid..ctor(String g) at Microsoft.OData.ODataPayloadValueConverter.ConvertStringValue(String stringValue, Type targetType) at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference) --- End of inner exception stack trace --- at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference) at Microsoft.Crm.Extensibility.ODataV4.CrmPrimitivePayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference) at Microsoft.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, Boolean validateNullValue, String propertyName, ODataPayloadValueConverter converter) at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadPrimitiveValue(Boolean insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, Boolean validateNullValue, String propertyName) at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideResourceValue, String propertyName, Nullable1 isDynamicProperty) at Microsoft.OData.JsonLight.ODataJsonLightParameterDeserializer.<>c__DisplayClass3_0.<ReadNextParameter>b__0(PropertyParsingResult propertyParsingResult, String parameterName) at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func2 readPropertyAnnotationValue, Action2 handleProperty) at Microsoft.OData.JsonLight.ODataJsonLightParameterDeserializer.ReadNextParameter(PropertyAndAnnotationCollector propertyAndAnnotationCollector) at Microsoft.OData.ODataParameterReaderCore.ReadImplementation() at Microsoft.OData.ODataParameterReaderCore.InterceptException[T](Func1 action) at Microsoft.Crm.Extensibility.ODataV4.CrmODataActionPayloadDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

Please advise if someone knows the root cause and how to fix it.

question from:https://stackoverflow.com/questions/65895924/exception-while-creating-quote-in-crm-using-generatequotefromopportunity-through

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Cannot convert the literal 'undefined' to the expected type 'Edm.Guid'. ---> System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

The above error message clearly says the GUID is not received as expected and instead 'undefined' text being sent. Make sure that is in correct format, exclude {} in guid content if any.

If it’s dynamic guid value, try to debug and hard code some known opportunity Id for troubleshooting. If you have plugin registered in that action, put some trace and/or use profiler for troubleshooting.

GUID is not something like password, so it’s not so secured and useless without other details. So you can share here and if needed change some characters or numbers in GUID, or even you can mask some of the characters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...