Views:

Example 1 - Basic JSON creation

Description: 

Shows how you can use fields on the Account entity to generate a JSON document.

Input:

CreateJObject(
               CreateJProperty('AccountName', [account.name]),  
               CreateJProperty('AccountNumber', [account.accountnumber]),  
               CreateJProperty('Address_Line1', [account.address1_line1]),  
               CreateJProperty('Address_Line2', [account.address1_line2]),  
               CreateJProperty('Address_Line3', [account.address1_line3]),  
               CreateJProperty('Address_City', [account.address1_city]),  
               CreateJProperty('Address_Zip', [account.address1_postalcode]),  
               CreateJProperty('Address_State', [account.address1_stateorprovince]),  
               CreateJProperty('Address_Country', [account.address1_country])
)

Output:

{
  "AccountName": "Advanced Components",
  "AccountNumber": "Acc-0000010021243111",
  "Address_Line1": "100 Red Oak Lane",
  "Address_Line2": "English athletes",
  "Address_Line3": "Top House",
  "Address_City": "Dallas",
  "Address_Zip": "20313",
  "Address_State": "TX",
  "Address_Country": "U.S."
}

Example 2 - Shows how to add defaults on fields & sub-objects

Description: 

Shows how you can use fields on the Account entity to generate a JSON document & how to construct sub JSON elements for Marketing data.   

Input:

CreateJObject(

                   CreateJProperty('AccountName', [account.name], ''),
                   CreateJProperty('AccountNumber', [account.accountnumber], ''),  
                   CreateJProperty('Address_Line1', [account.address1_line1], ''),
                   CreateJProperty('Address_Line2', [account.address1_line2], ''),
                   CreateJProperty('Address_Line3', [account.address1_line3], ''),
                   CreateJProperty('Address_City', [account.address1_city], ''),
                   CreateJProperty('Address_Zip', [account.address1_postalcode], ''),  
                   CreateJProperty('Address_State', [account.address1_stateorprovince], ''),  
                   CreateJProperty('Address_Country', [account.address1_country], ''),
                   CreateJProperty('MarketingData',
                            CreateJObject(
                                      CreateJProperty('DoNotBulkMail', [account.donotbulkemail]),
                                      CreateJProperty('DoNotBulkPostalMail', [account.donotbulkpostalmail]),
                                      CreateJProperty('DoNotEmail', [account.donotemail]),
                                      CreateJProperty('DoNotFax', [account.donotfax]), 
                                      CreateJProperty('DoNotPostalMail', [account.donotpostalmail]),
                                      CreateJProperty('DoNotPhone', [account.donotphone])
                                      ) 
                              )

                     ) 

Output:

{
  "AccountName": "Advanced Components",
  "AccountNumber": "Acc-0000010021243111",
  "Address_Line1": "100 Red Oak Lane",
  "Address_Line2": "English athletes",
  "Address_Line3": "Top House",
  "Address_City": "Dallas",
  "Address_Zip": "20313",
  "Address_State": "TX",
  "Address_Country": "U.S.",
  "MarketingData": {
    "DoNotBulkMail": "False",
    "DoNotBulkPostalMail": "False",
    "DoNotEmail": "False",
    "DoNotFax": "False",
    "DoNotPostalMail": "False",
    "DoNotPhone": "False"
  }
}

Example 3 - Shows how to add child nodes

Description: 

Shows how you can use fields on the Account entity to generate a JSON document & how to construct sub JSON elements for Marketing data. 

This example also shows how to add in child contact records into the JSON document.

Input:

CreateJObject(
                   CreateJProperty('AccountName', [account.name], ''),
                   CreateJProperty('AccountNumber', [account.accountnumber], ''),  
                   CreateJProperty('Address_Line1', [account.address1_line1], ''),
                   CreateJProperty('Address_Line2', [account.address1_line2], ''),
                   CreateJProperty('Address_Line3', [account.address1_line3], ''),
                   CreateJProperty('Address_City', [account.address1_city], ''),
                   CreateJProperty('Address_Zip', [account.address1_postalcode], ''),  
                   CreateJProperty('Address_State', [account.address1_stateorprovince], ''),  
                   CreateJProperty('Address_Country', [account.address1_country], ''),
                   CreateJProperty('MarketingData',
                            CreateJObject(
                                      CreateJProperty('DoNotBulkMail', [account.donotbulkemail]),
                                      CreateJProperty('DoNotBulkPostalMail', [account.donotbulkpostalmail]),
                                      CreateJProperty('DoNotEmail', [account.donotemail]),
                                      CreateJProperty('DoNotFax', [account.donotfax]), 
                                      CreateJProperty('DoNotPostalMail', [account.donotpostalmail]),
                                      CreateJProperty('DoNotPhone', [account.donotphone])
                                      ) 
                              ),
                CreateJProperty('Contacts', 
                            CreateJArrayChildren(
                                     FindRecords('contact', 'parentcustomerid', [account.accountid], '*' ),
                                     CreateJObject(
                                                   CreateJProperty('Fullname', FindJArrayItem('fullname')),
                                                   CreateJProperty('Jobtitle', FindJArrayItem('jobtitle')), 
                                                   CreateJProperty('Email', FindJArrayItem('emailaddress1')),
                                                   CreateJProperty('BusinessPhone', FindJArrayItem('telephone1'))
                                                             ) 
                                                           )
                                         ) 
                     ) 

Output:

{
  "AccountName": "Advanced Components",
  "AccountNumber": "Acc-0000010021243111",
  "Address_Line1": "100 Red Oak Lane",
  "Address_Line2": "English athletes",
  "Address_Line3": "Top House",
  "Address_City": "Dallas",
  "Address_Zip": "20313",
  "Address_State": "TX",
  "Address_Country": "U.S.",
  "MarketingData": {
    "DoNotBulkMail": "False",
    "DoNotBulkPostalMail": "False",
    "DoNotEmail": "False",
    "DoNotFax": "False",
    "DoNotPostalMail": "False",
    "DoNotPhone": "False"
  },
  "Contacts": [
    {
      "Fullname": "Bill Gates",
      "Jobtitle": "CTO",
      "Email": "bill.gates@microsoft.com",
      "BusinessPhone": "555-0135"
    },
    {
      "Fullname": "Steve Ballmer",
      "Jobtitle": "CEO",
      "Email": "steveb@microsoft.com",
      "BusinessPhone": "555-0138"
    }
  ]
}

Example 4 - Manually Load JSON - Single Values

Description:

Shows how you can manually load a JSON document from a field in CRM and then perform operations on the JSON document to build a plain string of data.

The 'responsecontent' is an internal variable that the North52 engine uses to process JSON data. So we can manually set this with any valid JSON document. Then we can use functions such as GetVarJsonValue() to retrieve the data points we are interested in.

Input:

SmartFlow(

  SetVar('responsecontent', [account.description]), 
  
  SetVar('JustAString', GetVarJsonValue('AccountName', '' ) + ' ' +
  
                GetVarJsonValue('MarketingData.DoNotPhone', '') + ' ' +
  
                GetVarJsonValue('Contacts{0}.Fullname', '')

  )

Output:

  "Advanced Components False Bill Gates"  

Contents of the field:  [account.description]

{
  "AccountName": "Advanced Components",
  "AccountNumber": "Acc-0000010021243111",
  "Address_Line1": "100 Red Oak Lane",
  "Address_Line2": "English athletes",
  "Address_Line3": "Top House",
  "Address_City": "Dallas",
  "Address_Zip": "20313",
  "Address_State": "TX",
  "Address_Country": "U.S.",
  "MarketingData": {
    "DoNotBulkMail": "False",
    "DoNotBulkPostalMail": "False",
    "DoNotEmail": "False",
    "DoNotFax": "False",
    "DoNotPostalMail": "False",
    "DoNotPhone": "False"
  },
  "Contacts": [
    {
      "Fullname": "Bill Gates",
      "Jobtitle": "CTO",
      "Email": "bill.gates@microsoft.com",
      "BusinessPhone": "555-0135"
    },
    {
      "Fullname": "Steve Ballmer",
      "Jobtitle": "CEO",
      "Email": "steveb@microsoft.com",
      "BusinessPhone": "555-0138"
    }
  ]
}

Example 5 - Manually Load JSON - Entity Collections

Description:

Shows how you can manually load a JSON document from a field in CRM and then perform operations on the JSON document like an entity collection.

Input:

SmartFlow(

  SetVar('Result', ''),
  
  SetVar('responsecontent', [account.description]), 
  
  ForEachRecord(

          GetVarJsonEC('Contacts'), 

          SetVarConcat('Result', ' ' + CurrentRecord('Email'))   
      )
  
  )    

Output:

  "bill.gates@microsoft.com steveb@microsoft.com"  

Contents of the field:  [account.description]

{
  "AccountName": "Advanced Components",
  "AccountNumber": "Acc-0000010021243111",
  "Address_Line1": "100 Red Oak Lane",
  "Address_Line2": "English athletes",
  "Address_Line3": "Top House",
  "Address_City": "Dallas",
  "Address_Zip": "20313",
  "Address_State": "TX",
  "Address_Country": "U.S.",
  "MarketingData": {
    "DoNotBulkMail": "False",
    "DoNotBulkPostalMail": "False",
    "DoNotEmail": "False",
    "DoNotFax": "False",
    "DoNotPostalMail": "False",
    "DoNotPhone": "False"
  },
  "Contacts": [
    {
      "Fullname": "Bill Gates",
      "Jobtitle": "CTO",
      "Email": "bill.gates@microsoft.com",
      "BusinessPhone": "555-0135"
    },
    {
      "Fullname": "Steve Ballmer",
      "Jobtitle": "CEO",
      "Email": "steveb@microsoft.com",
      "BusinessPhone": "555-0138"
    }
  ]
}

Example 6 - Manually Create Dynamic JArray 

Description:

Shows how you can manually create a dynamic JArray JSON document. 

Input:

SmartFlow(

 ForEachRecord(

          FindRecords('account', '*', '*', SetFindSelect('name', 'description')), 
  
          SetVarAppendJArray('myarray', CreateJObject( 
                                                           CreateJProperty('name', CurrentRecord('name')), 
                                                           CreateJProperty('description', CurrentRecord('description'))
                                                        )
                               )

         
             ),
  
  GetVar('myarray')

  )

Output:

[
  {
    "name": "Microsoft-Europe",     "description": "Super Cool A"   },
  {
    "name": "Microsoft-Ireland",     "description": "Super Cool B"   },
  {
    "name": "Microsoft-Cork",     "description": "Super Cool C"   } ]

Did you know?

North52 helps streamline complex healthcare processes

Healthcare providers are no strangers to complex processes and rules.  Patients expect efficient and seamless service. 

The North52 business rules engine helps healthcare providers implement complex rules in their Dynamics 365 systems quickly and without code. The rules are easily modified, tested and deployed as regulations and requirements change. 

Learn more about the North52 Decision Suite