Upsert into sub document in couchbase using N1QL - couchbase

I have document like below in couchbase.
{
"templateType": "EMAIL",
"displayName": "Email for user",
"structure": {
"{twitterLink}": "http://www.twitter.com/",
"{facebookLink}": "http://www.facebook.com",
"{instagramLink}": "http://instagram.com",
"{websiteLink}": "http://mavenir.com"
},
"backendPlaceholders": [
"{ACTIVATION_URL}",
"{USERNAME}"
]
}
I want to insert a new entry 'linkedIn' inside "structure" so that my doc will look like below,
{
"templateType": "EMAIL",
"displayName": "Email for user",
"structure": {
"{twitterLink}": "http://www.twitter.com/",
"{facebookLink}": "http://www.facebook.com",
"{instagramLink}": "http://instagram.com",
"{linkedIn}": "http://www.linkedin.com",
"{websiteLink}": "http://mavenir.com",
"{linkedIn}": "http://www.linkedin.com"
},
"backendPlaceholders": [
"{ACTIVATION_URL}",
"{USERNAME}"
]
}
May I know how to do it in N1QL ? The structure is not an array and it is a sub document. I am not sure how to do it in N1QL.

Use UPDATE statement
UPDATE default AS d
SET d.`structure`.`{linkedIn}` = "http://www.linkedin.com"
WHERE ....

Related

How to update a specific JSON element inside a complex JSON document in postgresql 10

I have JSON document which is stored under single column of type jsonb inside postgresql which looks like below:
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:100",
"resource": {
"resourceType": "Encounter",
"id": "110",
"status": "planned",
"priority": {
"coding": [
{
"code": "ASAP"
}
]
},
"subject": {
"reference": "Patient/123"
},
"appointment": [
{
"reference": "Appointment/12213#42"
}
],
"diagnosis": [
{
"condition": {
"reference": "Condition/condReferenceValue"
},
"use": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/diagnosis-role",
"code": "AD"
},
{
"system": "http://terminology.hl7.org/CodeSystem/diagnosis-role",
"code": "DD"
}
]
}
}
],
"hospitalization": {
"preAdmissionIdentifier": {
"system": "https://system.html"
}
},
"location": [
{
"location": {
"display": "Mumbai"
},
"status": "active"
},
{
"status": "planned"
}
]
},
"request": {
"method": "POST",
"url": "Encounter"
}
}
]
}
Now, I want to update value for reference under subject attribute. So, I tried below way but it throws an error:
update fhir.testing set names = jsonb_set(names,'{"subject":{"reference"','"Patient/1"',true) where id = 10;
Error:
SQL Error [22P02]: ERROR: malformed array literal: "{"subject":{"reference""
Detail: Unexpected array element.
I referred this link but didn't work out for me. How can I do it?
I don't use Postgres that much but from what i read in the relative jsonb_set example in the documentation of JSON functions (and since you want to update) shouldn't it be
jsonb_set(names, '{entry,0,subject,reference}','Patient/1', false)
instead of
jsonb_set(names,'{"subject":{"reference"','"Patient/1"',true)
jsonb
jsonb_set(target jsonb, path text[], new_value jsonb [, create_missing
boolean])
Returns target with the section designated by path replaced by
new_value, or with new_value added if create_missing is true (default
is true) and the item designated by path does not exist. As with the
path oriented operators, negative integers that appear in path count
from the end of JSON arrays.
EDIT
To explain the path used in jsonb_set, check this example.
jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]', false)
returns
[{"f1":[2,3,4],"f2":null},2,null,3]
As i understand if a sub-element in a complex JSON document is an array, you need to specify it's index e.g. 0,1,2,...
EDIT
Always look very carefully the structure of the JSON document. I simply write this because i did not see that subject was a child of resource and that is causing you the error.
So the correct path is actually '{entry,0,resource,subject,reference}'
Correct Query for your requirement is:
update fhir.testing
set names= jsonb_set(names, '{entry,0,resource,subject,reference}', '"Patient/1"' , false)
where id = 10;
Explanation
json_set takes 4 parameter
target_json (jsonb) - which accept jsonb type data. In your case it is names field.
path (text[]) - which accepts a text array. in your case it is '{entry,0,resource,subject,reference}'.
new_value (jsonb) - in your case you want to change it to '"Patient/1"'.
create_missing (boolean) - in your case it should be false. as you want to replace the existing one. if you want to create the reference with given value in case of not found then just mark it true.
the value is not valid json, try this out:
update fhir.testing set names = jsonb_set(names, '{"entry": [{"resource": {"subject":{"reference":"Patient/1"} }}]}',true) where id = 10;
You have to create a valid json, closing every { and every ], yours was
'{"subject":{"reference"'

Acumatica REST API - Create activity linked to customer

I am trying to programmatically add an activity to a customer entity. I can create both a customer and a note using the API with a PUT, but I cannot figure out how to relate the activity to the customer. I viewed the JSON definition using Postman, but didn't see anything that made sense for relating it to another entity. I tried adding RelatedEntityDescription, but that unsurprisingly did not work.
Here is my JSON body for the PUT (it works but creates an un-linked activity)
{
"Body": {
"value": "message text"
},
"Date": {
"value": "2020-04-22T15:28:00.99-05:00"
},
"Summary": {
"value": "Test message"
}
}
What do I need to add to link it to my customer?
Good day Sreimer
The Table you should be saving to is Note.
It links on BAccount.NoteID and Note.NoteID.
An easy way to test this is to create and save a note on a customers and look for it in Note:
select *
from Note
where NoteText like '%test%';
You just need to specify the RelatedEntityType and RelatedEntityNoteID in your request
{
"Body": {},
"Date": {
"value": "2021-01-06T14:42:03.837-08:00"
},
"RelatedEntityNoteID": {
"value": "01a0c017-df7f-ea11-8175-b9d61cb73193"
},
"RelatedEntityType": {
"value": "PX.Objects.AR.Customer"
},
"Summary": {
"value": "Test Activity 4"
},
"Type" : {
"value" : "M"
}
}

How to search azure table storage JSON response in logic app?

I am getting the below response from azure table storage. I need to search the response using the GeneralId and get the response true or false wheather an entity is available in table or not.
{
"odata.metadata": "https://google.net/$metadata#GetStudents",
"value": [
{
"odata.etag": "W/\"datetime'2019-05-01T18%3A04%3A37.5904256Z'\"",
"PartitionKey": "mypartitionkey",
"RowKey": "myrowkey",
"Timestamp": "",
"GeneralId": "456265d8-6c3b-11e9-a923-1681be663d3e",
"Inc": "PIR165461",
"Name": "",
"StudentId": "c17a3c42-6c48-11e9-a923-1681be663d3e",
"Subject": ""
},
{
"odata.etag": "W/\"datetime'2019-04-30T16%3A49%3A10.0746254Z'\"",
"PartitionKey": "par1",
"RowKey": "row1",
"Timestamp": "2019-04-30T16:49:10.0746254Z",
"Generald": "fada7dd0-6c48-11e9-a923-1681be663d3e",
"Inc": "PIR4237341",
"Name": "",
"StudentId": "c70c5de9-ac8d-4432-9f3c-1f8bede83504",
"Subject": ""
}
]
}
I guess you want to check if one entity exists in the table. So you could get the partition and row value from the json to check. Below is the workflow.
After Get Entities values, add a For each action, in the Input choose Dynamic content Get entities result List of Entities.
Then add Condition action to judge if the entity you want in the table. Use two condition, one is partition the other one is row vale.
After this you could add actions under If true or If false. And here is my test result.

Create a form with input controls dynamically from JSON using Angular 2

I need to create a form with controls dynamically from JSON using Angular 2.0.
I'm very new to Angular 2.0 and Typescript. I'm totally clueless, where to start with the development.
Any help is much appreciated.
Below is the sample JSON
"General": {
"None": [
{
"FieldName": "100",
"DisplayName": "Mapping Name",
"ClassSize": "col-sm-6 col-xs-12",
"Field": [
{
"ControlType": "TextBox",
"FieldClass": "col-sm-6 col-xs-12",
"Required": "True",
"MaxLength": "10",
"RegularExpression": ""
}
]
},
{
"FieldName": "101",
"DisplayName": "Select Target File Type",
"ClassSize": "col-sm-6 col-xs-12",
"Field": [
{
"ControlType": "Dropdown",
"FieldClass": "col-sm-6 col-xs-12",
"Required": "True",
"Options": [
{
"Description": "--Please select--",
"ID": 0
},
{
"Description": "Row Per Day",
"ID": 1
},
{
"Description": "Row Per Week",
"ID": 2
},
{
"Description": "Row Per Transaction",
"ID": 3
}
]
}
]
}
]
}
Create dynamic form group and loop through the json and create respective element, where forms input type and its related attributes(like name, value, placeholder,type,required,pattern etc) were varying as per resource's attributes. So render the forms at run time.
Reference information
Creating forms in angular 2 using json schema at run time
You will need to import a FormBuilder from #angular/forms. Then create a FormGroup.
public form: FormGroup;
private _buildForm() {
let obj = {};
General['None'].forEach(val => {
obj[val.fieldname] = new FormControl('', Validators.required);
});
_fb.group(obj);
}
On the template you will need loop through the form controls and and create the form based on the type.
This answer may not be give you all the answers you need but it's an eye opener on what you can do.
You may want to use FormArrays depending on how you'd want to implement.
Read through the angular2 documentation on forms. Also watch this video.
Angular 2 Forms | Kara Erickson - YouTube
Forms - ts - GUIDE - Angular

JSON is it best practice to give each element in an array an id attribute?

Is it best practice in JSON to give objects in an array an id similar to below?. Im trying to decide on a JSON format for a restful service im implementing and decide include it or not... If it is to be modified by CRUD operations is it a good idea?
{
"tables": [
{
"id": 1,
"tablename": "Table1",
"columns": [
{
"name": "Col1",
"data": "-5767703747778052096"
},
{
"name": "Col2",
"data": "-5803732544797016064"
}
]
},
{
"id": 2,
"tablename": "Table2",
"columns": [
{
"name": "Col1",
"data": "-333333"
},
{
"name": "Col2",
"data": "-44444"
}
]
}
]
}
Client-Generated IDs
A server MAY accept a client-generated ID along with a request to
create a resource. An ID MUST be specified with an "id" key, the value
of which MUST be a universally unique identifier. The client SHOULD
use a properly generated and formatted UUID as described in RFC 4122
[RFC4122].
jsonapi.org