Legacy Dev Forum Posts

 View Only

Sign Up

Microsoft Dynamics data action problem

  • 1.  Microsoft Dynamics data action problem

    Posted 06-05-2025 18:42

    scm_pa | 2021-04-05 19:53:36 UTC | #1

    Hi all. I’m working on a Dynamics data action for a customer and the response contains a json object that is converted to a string. I’m guessing on the D365 side it did a json.stringify() to store the information.

    { "@odata.context": REDACTED, "value": [ { "@odata.etag": "W/\"93668756\"", "proddinumber": "REDACTED", "proserviceconfiguration": "{\n \"Timezone\": \"Canada Central Standard Time\",\n \"Language\": 1050,\n \"DDINumber\": \"+1123456789\",\n \"CustomGreeting\": \"Hello World\",\n \"SpecialInstructions\": \"\",\n \"ShortDescription\": \"\",\n \"WebSite\": \http://www.google.com\,\n \"Contacts\": [\n {\n \"Id\": \"REDACTED\",\n \"FirstName\": \"Oliver\",\n \"LastName\": \"Jackson\",\n \"EMailAdress\": \REDACTED\,\n \"PrimaryPhoneNumber\": \"123-456\",\n \"SecondaryPhoneNumber\": \"123-789\",\n \"JobTitle\": \"Accountant\",\n \"AnswerFromDate\": \"2021-01-20\",\n \"AnswerToDate\": \"2021-05-20\",\n \"Priority\": 1\n },\n {\n \"Id\": \"REDACTED\",\n \"FirstName\": \"James\",\n \"LastName\": \"Williams\",\n \"EMailAdress\": \REDACTED\,\n \"PrimaryPhoneNumber\": \"456-123\",\n \"SecondaryPhoneNumber\": \"789-123\",\n \"JobTitle\": \"CEO\",\n \"AnswerFromDate\": \"2020-02-23\",\n \"AnswerToDate\": \"\",\n \"Priority\": 2\n }\n ]\n}", "proccaconfigurationid": "58e45f43-1c76-eb11-a812-0022487f678c", "proAccount": { "accountid": "REDACTED", "name": "A ONE INDUSTRIAL", "pro_titanid": "REDACTED" } } ] }

    I’m looking to extract some information from it and was looking to see if I can translate that back to a json object and set up the response template to get the data. I’ve been poking around the velocity macros to see if there was something there to do that but have not turned up anything yet. If anyone has had to handle this type of situation before I would be interested in seeing how you handled it.

    Thank you.


    Jason_Mathison | 2021-04-07 11:55:07 UTC | #2

    Hi scm_pa,

    Are you trying to get something out of the "pro_serviceconfiguration" part of the response?

    The JSON in the response you provided seems to be mangled. Could you either put that into a .json file and post the file to this thread, or else paste the response again, highlight it and then hit the </> button to configure it as preformatted text?

    --Jason


    scm_pa | 2021-04-07 12:20:58 UTC | #3

    Hi Jason,

    That is correct, I'm looking to pull information out of pro_serviceconfiguration. Thanks.

    { "@odata.etag": "W/\"115011743\"", "proddinumber": "447830611628", "proserviceconfiguration": "{\n \"Timezone\": \"Canada Central Standard Time\",\n \"Language\": 1050,\n \"DDINumber\": \"+1123456789\",\n \"CustomGreeting\": \"Hello World\",\n \"SpecialInstructions\": \"\",\n \"ShortDescription\": \"\",\n \"WebSite\": \"http://www.google.com\",\n \"Contacts\": [\n {\n \"Id\": \"6bb9c6f9-7654-4b5d-a07f-2bbe8cbff489\",\n \"FirstName\": \"Oliver\",\n \"LastName\": \"Jackson\",\n \"EMailAdress\": \"oliver.jackson@iwg.com\",\n \"PrimaryPhoneNumber\": \"123-456\",\n \"SecondaryPhoneNumber\": \"123-789\",\n \"JobTitle\": \"Accountant\",\n \"AnswerFromDate\": \"2021-01-20\",\n \"AnswerToDate\": \"2021-05-20\",\n \"Priority\": 1\n },\n {\n \"Id\": \"dd22bab8-20e9-436e-95cb-21507436efa3\",\n \"FirstName\": \"James\",\n \"LastName\": \"Williams\",\n \"EMailAdress\": \"james.williams@iwg.com\",\n \"PrimaryPhoneNumber\": \"456-123\",\n \"SecondaryPhoneNumber\": \"789-123\",\n \"JobTitle\": \"CEO\",\n \"AnswerFromDate\": \"2020-02-23\",\n \"AnswerToDate\": \"\",\n \"Priority\": 2\n }\n ]\n}", "proccaconfigurationid": "58e45f43-1c76-eb11-a812-0022487f678c", "proAccount": { "accountid": "821e5a34-b72d-ea11-a810-000d3a3a76f4", "name": "A ONE INDUSTRIAL", "pro_titanid": "10115575" } }


    Jason_Mathison | 2021-04-09 19:18:12 UTC | #4

    Hi scm_pa,

    It would be great if we had a data action tool to take care of this. Please open up an idea for this to see how widespread the interest would be: https://genesyscloud.ideas.aha.io/

    Another option is to use a AWS lambda to do this, since going from escaped JSON back to JSON is probably trivial.

    Finally, we can try to convert the escaped JSON into regular JSON via string manipulation. This works for the example you gave, but it likely to be more fragile than a formal tool to unescape the JSON.

    { "translationMap": { "proserviceconfiguration": "$.proserviceconfiguration" }, "translationMapDefaults": {}, "successTemplate": "$proserviceconfiguration.substring(1, $math.sub($proserviceconfiguration.length(), 1)).replaceAll('\\\\\\\"', '\\\"').replaceAll('\\\\r', '').replaceAll('\\\\n', '').replaceAll('\\\\\\\\', '\\\\').replaceAll('\\\\b', '').replaceAll('\\\\f', '').replaceAll('\\\\t', '')" }

    This will return the proserviceconfiguration as an JSON object. You will need to setup the output contract to mirror the match proserviceconfiguration output. If you wanted to include other values in the output you could probably change the $math.sub($proserviceconfiguration.length(), 1) to $math.sub($proserviceconfiguration.length(), 2) to exclude the final } and then add your key value pairs and add a final } at the end.

    --Jason


    scm_pa | 2021-04-09 20:16:20 UTC | #5

    Hi Jason. Thank you for that. I will definitely submit the idea. We talked with the customer who is going to make a change on their end to de-serialize that into an object. We discussed the parsing idea with them and all parties came to the same conclusion that you pointed out about it being fragile and problematic long term.

    Regards.


    system | 2021-05-10 20:16:20 UTC | #6

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 10497