Add extra attribute to object Logic app - azure-logic-apps

Im trying to add an extra attribute to the respons object in logic app.
I got 2 shape that sending request to two different http.
In the third shape i want to merge the body from one respons with the other respons.
Like below
"ResponsBody":{
"title": "",
"created": "",
"priority": "",
"Category": "",
"summary": ""
}
So want i want take the ID from one of respons and merge it with the other one.
{
"ID":""
"title": "",
"created": "",
"priority": "",
"Category": "",
"summary": ""
}
So far this is what i get.
23123{"title": "","created": "","priority": "","Category": "","summary":""}
the ID is outside.
Code in Logic app:
"body": "#{triggerBody()?['ID']}#{body('Get_HTTP_Info')?['data']}"

You can use the #union function to merge two objects
"body": "#union(triggerBody(), body('Get_HTTP_Info'))"
To add specific properties only, you can first use a compose action to prepare the content
"compose1": {
"type": "compose"
"inputs": { "id": "#triggerBody()['Id']"}
}
And then you can do
"body": "#union(outputs('compose1'), body('Get_HTTP_Info'))"

Related

Karate: simplest way to validate value of array json response should not be empty

response= [
{
"id": "123",
"name: "user1",
"location": "USA"
},
{
"id": "133",
"name: "user2",
"location": "CANADA"
},
{
"id": "",
"name": "user3",
"location": "INDIA"
}
]
I am trying to validate the above json array using the schema and want to validate that values of my keys should not be empty or blank.
I am using the below code:
* def schema = {"id": "#notnull", "name": "#notnull", "location": "#notnull"}
* match each response contains schema
But even though my response has "id":"" -- id is empty/blank in the 3rd index in json array. Still I get a pass in my scenario.
Is this the correct way or is there any other way to handle empty values in schema for a json array response.
Your help would be appreciated.
Thank you
Ideally we should have #notblank but we don't because it is so rare.
Do this instead:
* match each response contains { id: "#? _ != ''" }

How to convert json objects to json array in flutter

This is my json response data. I would like to display this data in listview using map but i dont know how to convert the objects of objects to array of data.
{
"success": true,
"data": {
"addresses": {
"abc": {
"address_id": "121",
"firstname": "Demo",
"lastname": "User",
"company": "Demo Company name",
"telephone": "1-541-754-3011",
"address_1": "Demo",
"address_2": "test address",
"postcode": "3333",
"city": "Berlin",
"zone_id": "1256",
"zone": "Berlin",
"zone_code": "BER",
"country_id": "81",
"country": "Germany",
"longitude": "",
"lattitude": "",
"iso_code_2": "DE",
"iso_code_3": "DEU",
"address_format": "{company}\r\n{firstname} {lastname}\r\n{address_1}\r\n{address_2}\r\n{postcode} {city}\r\n{country}",
"custom_field": null
}
}
}
}
I assume you want to display dynamic keys (eg: abc) inside addresses object. For this, you need to iterate through addresses object for keys and values.
//json you provide
addresses = json["data"]["addresses"];
addresses.forEach((final String key, final value) {
//here key will be abc & value will be json object
//you can add key or value to a different list and use for list rendering later
});
You can use JSON to dart tool, which is available online for free.
Paste your JSON to left panel and select dart language from upper right corner,
You will get your dart class code, in which you can use methods like .toMap() and .toJson(),
This can be very helpful for huge JSON data.

How to update a double nested value inside an array of multiple documents?

Imagine the following collection of city records:
{
"city": "London",
"inhabitants": [
{
"id": "34543534",
"user": {
"name": "Jonathan Deer",
"email": "john#btinternet.com"
}
},
{
"id": "0454534",
"user": {
"name": "Tanya Patel",
"email": "tanya#btinternet.com"
}
},
{
"id": "4345345",
"user": {
"name": "Catherine King",
"email": "catherine#gmail.com"
}
}
]
}
{
"city": "Manchester",
"inhabitants": [
{
"id": "980003",
"user": {
"name": "Benjamin Thaw",
"email": "benny#btinternet.com"
}
},
{
"id": "734488",
"user": {
"name": "Craig Longstone",
"email": "craig#gmail.com"
}
},
{
"id": "4400093",
"user": {
"name": "Arnold Greentree",
"email": "arnold#btinternet.com"
}
},
]
},
What I'm trying to do is loop through each inhabitants array of each city, and see if any of the people there has an email address containing btinternet.com in it. For those users I want to sent a new flag isBT: true and for everyone else (e.g., gmail.com users) isBT: false:
"user": {
"name": "Tanya Patel",
"email": "tanya#btinternet.com"
"isBT" true
}
I tried the following queries - first query sets all of them to isBT: false while the second one searches for "btinternet.com" in email address and sets isBT: true:
db.city.update({ "inhabitants.user.email": {$exists: true}}, {$set: { "inhabitants.$.user.isBT": false}}, {multi: true})
db.city.update({ "inhabitants.user.email": {$regex: "btinternet.com"}}, {$set: { "inhabitants.$.user.isBT": true}}, {multi: true})
The problem is that when I execute the second query, there are several inhabitants records that are left with isBT: false even though they contain the necessary "btinternet.com" email address. It almost seems like only the first user record that matches the criteria gets updated... Is there a way to update ALL user records for all "inhabitants" arrays?
I looked at using the positional operator $[], but our DB is on version 2.6.3 but this operator was introduced only in 3.6...
The short answer is "no".
The long answer is "no, because your MongoDB version doesn't support such an operation". You'll need to either...
1. retrieve all matching documents and perform a full array update through server-side processing of the data (e.g. use the MongoDB cursor.forEach()),
2. extend your match for "inhabitants.user.isBT": true (use
$elemMatch) and repeatedly perform the update query until the
number of modified documents is 0 (i.e. there are no more array
elements to update), or
3. update your MongoDB version and any
server-side code that relies on features of the current version that
have changed between 2.6 and 3.6.
Any solution to this problem will require more effort than a single query. There's no getting around it. It's a tough pill to swallow, but there really isn't a nice alternative.

Docusign REST API MERGE FIELD - SALESFORCE

Im trying to prefill my document with salesforcse Lead Name, however i cant accomplish it, the signHereTabs, and dateSignedTab is showing but the
texttabs dont get any data,
The REST API Documentation https://docs.docusign.com/esign/restapi/CustomTabs/CustomTabs/create/#request
says: that the row field is the "Specifies the row number in a Salesforce table that the merge field value corresponds to." but if i pass the salesforce record id im getting the error:
DocuSign Response{
"errorCode": "INVALID_REQUEST_PARAMETER",
"message": "The request contained at least one invalid parameter. int value expected for parameter: mergeField.row"
}
This is my json request:
{
"emailSubject": "Agreement",
"emailBlurb": "MSTSolutions is sending you this request for your electronic signature and enter or update confidential payment information.Please review and electronically sign by following the link below.",
"templateId": "42a4815d-f8ac-4972-b1ea-2e1534324658",
"envelopeIdStamping": "false",
"templateRoles": [{
"roleName": "Signer 1",
"name": "TEST TEST",
"email": "xxx#xxxx.com",
"recipientId": "1",
"tabs": {
"signHereTabs": [{
"xPosition": "25",
"yPosition": "50",
"documentId": "1",
"pageNumber": "1"
}],
"dateSignedTabs": [{
"name": "Date Signed",
"xPosition": "25",
"yPosition": "100",
"documentId": "1",
"pageNumber": "1"
}],
"textTabs": [{
"tabLabel": "LeadFirstName",
"xPosition": "25",
"yPosition": "200",
"documentId": "1",
"pageNumber": "1",
"mergeField": {
"configurationType":"Salesforce",
"path":"Lead",
"row":"00Q29000003fI13",
"writeback":"true",
"allowSenderToEdit":"true",
}
}]
}
}],
"status": "sent"
}
Thanks
Fairly sure the error is is how your path is configured. Try this:
"path": "Lead.FirstName"
and then remove the "Row" line
If you use the 'GET /v2/accounts/{accountId}/envelopes' create endpoint you can pass in the lead/opportunity/account Ids via the "Custom Fields" section. This will set all custom Salesforce fields you have defined in the template (relating to the SFIDs you provide) without having to set each tab one by one.
"customFields":{
"textCustomFields":[
{
"value":"0060n00000DIvfNAAT",
"name":"Opportunity",
"configurationType":"salesforce"
}
]
}
Note the textCustomFields is enclosed in a customFields block (which matches the published API) and most importantly, the configuration type must be set to "salesforce" and the Name must be "Opportunity" (etc) without the ##SF prefix which appears in a lot of examples on the web (for the SOAP api). By examining the 'GET /v2/accounts/{accountId}/envelopes/{envelopeId}/custom_fields' endpoint you can see that the API is automatically afixing the ##SF prefix and modifying the Value to include the record name:
{
"textCustomFields": [
{
"fieldId": "10140751586",
"name": "##SFOpportunity",
"show": "false",
"required": "false",
"value": "0060n00000DIvfNAAT~Test Opp Lisa Simpson"
}
}

Concatenation of JSON Arrays/Objects using Groovy

How can two independent different JSON Arrays or JSON Objects be merged or concatenated and treated as a single JSON Object using Java or Groovy.
See below sample JSON independent Objects i have
First one holds Duties information
[
{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}]
Second JSON object holds Certificates infomation
[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}]
I need to concatenate and access both the JSONs in below format `
{
"duties":
[{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}],
"Certificates":
[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}
]
}
Please let me know the option available to get this done. Thanks
It can be done e.g. in the following way:
import groovy.json.*
def json1 = """[
{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}]"""
def json2 = """[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}]"""
def duties = new JsonSlurper().parseText(json1)
def certs = new JsonSlurper().parseText(json2)
println JsonOutput.prettyPrint(JsonOutput.toJson ([duties: duties, certificates: certs]))

Resources