web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Create record in Dynam...
Power Automate
Answered

Create record in Dynamics 365 for Operations

(0) ShareShare
ReportReport
Posted on by

Hi,

 

I'm trying to create a record in Dynamics 365 for Operations every time a new message arrives in an Azure Service Bus Queue.

 

I use a Service Bus Service trigger connected to the Azure Service Bus queue and a Dynamics 365 for Operations Service for creating the record in my Dynamics 365 for Operations instance.

 

The message I receive looks like this:

 

snip_20170124124604.png

 

The message that was originally added to the Service Bus queue is encoded as a base64 string and is included in the received message in Flow as content. How do I access the data in the original message (in the base64 encoded string) when creating the record in Dynamics 365 for Operations?

 

snip_20170124125044.png

Categories:
I have the same question (0)
  • v-yamao-msft Profile Picture
    on at
    Hi Henning, Could you try with a flow using this template to see if you would still get the same error message? https://flow.microsoft.com/en-us/galleries/public/templates/f0d9695094f411e6857213a3d67e3c3e/copy-dynamics-crm-accounts-to-customers-in-dynamics-365-for-operations/ Best Regards, Mabel Mao
  • Community Power Platform Member Profile Picture
    on at

    Hi Mabel Mao,

     

    Thank you for youranswer. I'm not sure which error message you're referring to. I don't get any errors and I can easily create records in Dynamics 365 for Operations using hard coded values. Maybe my explanation wasn't clear enough.

     

    My problem is this: How do I get access to values from the base 64 encoded inner message (Content data) that arrives from the service bus queue?

     

    Best regards 

     

    Henning

  • Steewee Profile Picture
    6 on at

    Hi,

     

    I have the same problem but actively looking for a solution. If I find I'll know.

    I am getting data from service Bus and want to create new Dynamics 365 record from that. No way, no help, nothing...

     

    Stefan

  • Steewee Profile Picture
    6 on at

    Hi Henning, I am CRM specialist, so I've tried a message from Service Bus Queue create a new Dynamics 365 (CRM) Account or Contact record.

     

    This is my test code in console app. Important is ContentType = "account" in my case (or "contact").

    sb2crm1.PNG

    As you can see, the Service Bus message Content is just a string "SB 2 CRM...."

    sb2crm2.PNG

    So, that is for now. But I am not satisfied with this result, I will investigate further.

  • michowl Profile Picture
    Microsoft Employee on at

    Try using the Compose action with some type conversion

    https://docs.microsoft.com/en-us/rest/api/logic/definition-language#functions

     

    Under conversion functions, there is base64 to string and I think string to json.

    Once you convert to Json, you should be able to navigate to the property you want.

     

    Something along the lines of:

    "@json(decodeBase64(body('When_a_message_is_recieved_in_a_queue')?.Content))?.ContentDateTime"

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    Hi,

     

    Thank you very much for pointing me in the right direction. I've solved the problem using the Compose component as you suggested. Smiley Happy

     

    When receiving a message from the queue I run the following code to decode the message to a string:

     

    "@base64tostring(triggerBody()?['ContentData'])"

     

    The string can not be converted to a json-object since it contains to much information so I needed to take a substring from the first '{' to the last '}' (both included). 

     

    The index of the first '{' is found in a component called "FirstIndex" by:

     

    "@indexof(base64tostring(triggerBody()?['ContentData']),'{')"

     

    And the index of the last '}' is found in a component called "LastIndex" by:

     

    "@lastindexof(base64tostring(triggerBody()?['ContentData']),'}')"

     

    Putting it all together to get a string that can be parsed as a json object, we get:

     

    "@substring(base64tostring(triggerBody()?['ContentData']),outputs('FirstIndex'), add(sub(outputs('LastIndex'),outputs('FirstIndex')),1))"

     

    Then the individual parameters in the output from "SubString" can be accessed by:

     

    "@json(outputs('SubString'))?.DeviceId" (where 'DeviceId' is the name of the parameter) in a component called "DeviceId". Then the device Id can be accessed by inserting the following in a field in the component for creating a record in Dynamics 365 for Operations:

     

    "@outputs('DeviceId')" 

     

    The " " around the code MUST be included - otherwise it won't work (and yes, they're not visible when the flow has been saved).

     

    All in all it looks like this:

     

    snip_20170131132525.png 

     

  • michowl Profile Picture
    Microsoft Employee on at

    Glad it worked!

    Surprised you couldn't just convert the string directly to JSON.

     

    I have one more tip that might make your flow run more quickly:

    Do the base64toString conversion once and store it in a Compose variable

  • Community Power Platform Member Profile Picture
    on at

    Hi,

     

    Well, the content data decoded to a string looks like this:

     

    @string3http://schemas.microsoft.com/2003/10/Serialization/��{"DeviceId":"MyTempLogger","EventTime":"1485851525","MTemperature":26.92,"Pressure":1019.559814,"Humidity":25.431641,"EventProcessedUtcTime":"2017-01-31T08:32:06.7338449Z","PartitionId":1,"EventEnqueuedUtcTime":"2017-01-31T08:32:06.7980000Z","IoTHub":{"MessageId":null,"CorrelationId":null,"ConnectionDeviceId":"MyTempLogger","ConnectionDeviceGenerationId":"636153496435175112","EnqueuedTime":"0001-01-01T00:00:00.0000000","StreamId":null}}

     

    Only the part between '{' and '}' (both included) can be converted to a json object, so I had to create the substring to get it right. Smiley Happy

     

    You're right about doing the base64tostring once. I will. Smiley Very Happy

  • gouravjain00786 Profile Picture
    4 on at

    Hello All,

    I am also stuck in creating the record. Can you please tell me step by step configuration.

    Hope for quick response

  • Community Power Platform Member Profile Picture
    on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard