Search code examples
azureazure-functionsdynamics-crm

How do we update this JSON in CRM through Azure Function


The json I need to copy:

{
  "id": "C76B4E57-5BAC-EA11-A812-000D3AD773FF",
  "name": "3000005170",
  "description": "\"\"FISHING-TV\" LLC Support",
  "status": "Active",
  "statusReason": "Active",
  "engagedParty": {
    "id": "ae8e617a-45ac-ea11-a812-000d3ad773ff",
    "name": "\"\"FISHING-TV\"  LLC",
    "@referredType": "Organization"
  },
  "agreement": [
    {
      "id": "7a94566e-73b1-ea11-a812-000d3ab958aa",
      "name": "201498-0000 <D365 UI: Contract.SES TN  DB: opportunity.ses_sestn  Comment: >"
    }
  ],
  "characteristic": [
    {
      "name": "industry",
      "value": "broadcaster",
      "valueType": "string"
    },
    {
      "name": "preferredPartner",
      "value": false,
      "valueType": "boolean"
    },
    {
      "name": "commercialRegisterNumber",
      "value": "265518057129",
      "valueType": "string"
    },   
    {
      "name": "bvdIdNumber",
      "value": "CHCHE395074263",
      "valueType": "string"
    },    
    {
      "name": "taxNumber",
      "value": "345678",
      "valueType": "string"
    },    
    {
      "name": "language",
      "value": "RU",
      "valueType": "string"
    },
    {
      "name": "currency",
      "value": "EUR",
      "valueType": "string"
    },
    {
      "name": "preferredMethodOfContact",
      "value": "Any",
      "valueType": "string"
    }
  ],
  "contactMedium": [
    {
      "mediumType": "telephoneNumber",
      "preferred": true,
      "<D365": null,
      "Comment": "Default",
      "address": "in",
      "the": "contact",
      "form": ">",
      "characteristic": {
        "contactType": "standard",
        "phoneNumber": "+38380977008558"
      }
    },
    {
      "mediumType": "faxNumber",
      "preferred": true,
      "<D365": null,
      "Comment": "Default",
      "address": "in",
      "the": "contact",
      "form": ">",
      "characteristic": {
        "contactType": "standard",
        "faxNumber": "+765478965"
      }
    },
    {
      "mediumType": "emailAddress",
      "preferred": true,
      "<D365": null,
      "Comment": "Default",
      "address": "in",
      "the": "contact",
      "form": ">",
      "characteristic": {
        "contactType": "standard",
        "emailAddress": "[email protected]"
      }
    },
    {
      "mediumType": "postalAddress",
      "preferred": false,
      "characteristic": {
        "contactType": "billing",
        "street1": "street one",
        "postCode": "65478",
        "postOfficeBox": "9756",
        "city": "Den Hauge",
        "stateOrProvince": "South Hollad",
        "country": "FR",
        "phoneNumber": "9859755",
        "phone2": "65478",
        "faxNumber": "54632"
      }
    },
    {
      "mediumType": "postalAddress",
      "preferred": true,
      "<D365": null,
      "Comment": "Default",
      "address": "in",
      "the": "contact",
      "form": ">",
      "characteristic": {
        "contactType": "standard",
        "street1": "34 Lesi Ukrainky Blvd.",
        "street2": "test1",
        "street3": "test2",
        "postCode": "05000",
        "postOfficeBox": "Test",
        "city": "Almaty",
        "stateOrProvince": "VAS",
        "country": "FR"
      }
    }
  ],
  "sanctionProfile": [
    {
      "sanctionProfileProvider": "VISUAL COMPLIANCE",
      "sanctionIssuerCountry": "\"AU <D365 UI: Country regulation.Genaral.Regulations contries.ISO code 1  DB: ses_country.ses_isocode1  Comment: ISO Code for countries, plus \"EU\" and \"UN\"> \"",
      "isSanctioned": true,      
      "creationDate": "2020-06-12T10:35:45.335Z <D365 UI: account.Finance & Legal.Embargo Status.Status Reason DB: ses_embargostatus.createdon  Comment: 1 to M relationShip > "
    },
    {
      "sanctionProfileProvider": "VISUAL COMPLIANCE",
      "sanctionIssuerCountry": "\"EU <D365 UI: Country regulation.Genaral.Regulations contries.ISO code 1  DB: ses_country.ses_isocode1  Comment: ISO Code for countries, plus \"EU\" and \"UN\"> \"",
      "isSanctioned": false,      
      "creationDate": "2020-06-12T10:35:45.335Z <D365 UI: account.Finance & Legal.Embargo Status.Status Reason DB: ses_embargostatus.createdon  Comment: 1 to M relationShip > "
    },
    {
      "sanctionProfileProvider": "VISUAL COMPLIANCE",
      "sanctionIssuerCountry": "\"US <D365 UI: Country regulation.Genaral.Regulations contries.ISO code 1  DB: ses_country.ses_isocode1  Comment: ISO Code for countries, plus \"EU\" and \"UN\"> \"",
      "isSanctioned": false,      
      "creationDate": "2020-06-12T10:35:45.335Z <D365 UI: account.Finance & Legal.Embargo Status.Status Reason DB: ses_embargostatus.createdon  Comment: 1 to M relationShip > "
    },
    {
      "sanctionProfileProvider": "VISUAL COMPLIANCE",
      "sanctionIssuerCountry": "\"UK <D365 UI: Country regulation.Genaral.Regulations contries.ISO code 1  DB: ses_country.ses_isocode1  Comment: ISO Code for countries, plus \"EU\" and \"UN\"> \"",
      "isSanctioned": true,      
      "creationDate": "2020-06-12T10:35:45.335Z <D365 UI: account.Finance & Legal.Embargo Status.Status Reason DB: ses_embargostatus.createdon  Comment:> "
    }
  ],
  "creditProfile": [
    {
      "creditProfileProvider": "BRADSTREET < = static value BRADSTREET or BWD?>",
      "creditRiskRating": "Market"
    }
  ],
  "relatedParty": [
    {
      "id": "6226ae2b-3ccd-ea11-a812-000d3ad773ff",
      "name": "John R. Doe",
      "role": "contact24h7d",
      "@referredType": "Individual<D365 Comment:default value, Doesn't exist in the system> "
    },
    {
      "id": "6226ae2b-3ccd-ea11-a812-000d3ad773ff",
      "name": "Billy W. Evans",
      "role": "billing",
      "@referredType": "Individual<D365 Comment:default value, Doesn't exist in the system> "
    },
    {
      "id": "a0925eaa-6bca-ea11-a812-000d3ad773ff",
      "name": "Peter T. Arain",
      "role": "cam",
      "@referredType": "Employee"
    }
  ],
  "validFor": { "startDateTime": "2018-06-11T10:35:45.335Z" }
}

Solution

  • You can prepare a C# class using your Json template. This class is your model and will have all the nodes/attributes including related records list (Expando objects)

    In Azure function, you have to deserialize the Json using Newtonsoft.Json into your above C# class object. Read more

    After that, like I explained in your other question, you have to initialize CRM entity object to create/update them.