cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Barry_Francis
Level: Powered On

PowerApps to Dynamics 365 Mapping errors

Hi community,

 

Expectation: I am creating a PowerApp that is meant to create a custom entity called "Timesheet".

I created a blank edit form that pulls from the new_timesheet entity, as well as the new_project, new_backlogitem, systemuser and account entity.

 

Timesheet edit form.jpg

 

As there are lookups, I created another two screens that when a user selects the Search icon under projects or backlog items, they fade to these lists where they can search for a record and then select it into the above 'lookup' field

* Select icon(ClearCollect(projectToBeAdded , ThisItem);Back())

* If(IsBlank(First(projectToBeAdded).new_projectid),Blank(),First(projectToBeAdded).new_name)

* Navigate(Projects,ScreenTransition.Fade,{searchnew_name : DataCardValue1 .Text});Clear(projectToBeAdded)

 

Then I tried to use a patch function to write through the form through to Dynamics 365: 

Patch(' Timesheets',Defaults('Timesheets'),{new_name: DataCardValue3.Text, new_date: DataCardValue16.SelectedDate, new_billable: DataCardValue22.Value, new_timespent:Value(DataCardValue17.Text)})

All the above allowed me to create the record in Dynamics 365, but without the 'lookups' being populated as I couldn't figure out how to do this.

 

So I tried Flow from OnSelect of the button, however, I get the following errors on the date and lookup field mappings:

Date:"status"400,
  "message""An error occurred while validating input parameters: Microsoft.OData.ODataException: Cannot convert the literal 'utcNow()' to the expected type 'Edm.Date'. ---> System.FormatException: String 'utcNow()' was not recognized as a valid Edm.Date.\r\n   at Microsoft.OData.PlatformHelper.ConvertStringToDate(String text)\r\n   at Microsoft.OData.ODataPayloadValueConverter.ConvertStringValue(String stringValue, Type targetType)\r\n   at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference)\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, Boolean validateNullValue, String propertyName, ODataPayloadValueConverter converter)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadPrimitiveValue(Boolean insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, Boolean validateNullValue, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadEntryDataProperty(IODataJsonLightReaderResourceState resourceState, IEdmProperty edmProperty, String propertyTypeName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass4_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtNestedResourceInfoEndImplementationSynchronously()\r\n   at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n   at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n   at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)",
  "source""[ORGNAME].crm4.dynamics.com",
  "errors": [],

 

Lookup:   "status"400,
  "message""Bad Request - Error in query syntax.",
  "source""[ORGNAME].crm4.dynamics.com",
  "errors": [],

 

Does anyone know how I could resolve this? I am really not sure how to set the patch lookup mappings or how to resolve flow if its not happy with the date format or the lookup resolving.

1 ACCEPTED SOLUTION

Accepted Solutions
Barry_Francis
Level: Powered On

Re: PowerApps to Dynamics 365 Mapping errors

I managed to figure out the issue and build a blog post on my findings, check it out: Basic Guide to PowerApps

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: PowerApps to Dynamics 365 Mapping errors

The UtcNow function is passing incorrect time format whe ncreating new records in Dyanmics 365, please review the following thread for how to work with times when creating new record in Microsoft Flow:

Create a new record in Dynamics 365

 

Further, the lookup field in Dyanmics 365 requires to be updated with the lookup entity record ID, for example, if Timesheet entity has an Account Lookup field, then we need to fill in that field with the corresponding AccountID.

The detailed explanation is documented in the blog below:

Working with Dyanmics 365 Lookup fields in PowerApps

 

If you have any further questions, please post back.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Barry_Francis
Level: Powered On

Re: PowerApps to Dynamics 365 Mapping errors

Hi Michael,

 

Thank you for the reply.

 

Firstly, the date conversion didn't seem to work in flow.

 

I followed the steps exactly and I still got the same error:

{
"status": 400,
"message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: Cannot convert the literal '2018-07-31T00:00:00.0000000Z' to the expected type 'Edm.Date'. ---> System.FormatException: String '2018-07-31T00:00:00.0000000Z' was not recognized as a valid Edm.Date.\r\n at Microsoft.OData.PlatformHelper.ConvertStringToDate(String text)\r\n at Microsoft.OData.ODataPayloadValueConverter.ConvertStringValue(String stringValue, Type targetType)\r\n at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference)\r\n --- End of inner exception stack trace ---\r\n at Microsoft.OData.ODataPayloadValueConverter.ConvertFromPayloadValue(Object value, IEdmTypeReference edmTypeReference)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, Boolean validateNullValue, String propertyName, ODataPayloadValueConverter converter)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadPrimitiveValue(Boolean insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, Boolean validateNullValue, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadEntryDataProperty(IODataJsonLightReaderResourceState resourceState, IEdmProperty edmProperty, String propertyTypeName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass4_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)",
}

 

I even tried different time zones. Could it be that I am not doing it in the correct order?

DateFormateError.jpg

 

 

With regards to the lookup part, I was missing the last part whereby the card itself needs to have an Update set.

 

After I added in this, I assumed it would attribute the DataCardValue with the ID I wanted to pass through, not the name of the record. However, the name is still being pushed through in the flow action mapping. Here are some more details:

 

1. DataCardValue function: If(IsBlank(First(backlogToBeAdded).BackLogItems.ec_ecbacklogitemid),Blank(),First(backlogToBeAdded).BackLogItems.ec_name)

2. Search Icon function

Navigate(BacklogItems,ScreenTransition.Fade,{searchec_name : DataCardValue20 .Text});Clear(backlogToBeAdded)

3. Select record icon function

ClearCollect(backlogToBeAdded , {BackLogItems :BrowseGallery1.Selected});Back()

4. Data Card function

First(backlogToBeAdded).BackLogItems.ec_ecbacklogitemid

5. Flow run function mapping

PowerAppsbutton.Run(DataCardValue20, DataCardValue19, DataCardValue16, DataCardValue3, DataCardValue21, DataCardValue22, DataCardValue17)

(Where DataCardValue20 is linked to the Backlog Item lookup field)

 

Here is the error I am getting:

{
"status": 400,
"message": "')' or ',' expected at position 4 in '(UX Lead)'.",
}

 

Backlog Item error.jpg

Barry_Francis
Level: Powered On

Re: PowerApps to Dynamics 365 Mapping errors

Hi Michael,

 

Just to give more information, I realized that I was using a date field with a date time zone set to: Local. I have since tried UTC, but am still receiving the same error.

 

I have tried using different time zones and adding .SelectedDate to the mapping when pushing it through Flow.

 

Each time I have seen the same error.

 

I have however figured out the mapping for the Dynamics 365 Lookup mapping: _ec_backlogitemid_value_DataCard3.Update. This has allowed me to push through the ID that was saved on the data card.

Barry_Francis
Level: Powered On

Re: PowerApps to Dynamics 365 Mapping errors

I managed to figure out the issue and build a blog post on my findings, check it out: Basic Guide to PowerApps

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,411)