Logic Apps - I can create a row in dataverse with null in lookup field, but i can't update a row with null - azure-logic-apps

When I use the dataverse connector 'create a row (preview)', I can create a row in the table 'Account' with the field 'primarycontactid' null. When I try do this with 'update a row (preview)' however, I get an error:
{
"error": {
"code": "0x80060888",
"message": "The supplied reference link -- -- is invalid. Expecting a reference link of the form /entityset(key)."
}
}
this is the body:
"body": {
"name": "Test2",
"primarycontactid#odata.bind": ""
}
When I adjust the code itself to "primarycontactid#odata.bind": null, it works.
but i need to have something like this (so this works on create, not update):
"primarycontactid#odata.bind": "#{if(empty(body('Get_Contact')?['value']),null,concat('contacts(',body('Get_Contact')?['value']?[0]?['contactid'] ,')'))}"
I tried filling it with null, with empty quotes, with contacts(00000000-0000-0000-0000-000000000000) but nothing works.

After reproducing from my end, I have received the same error but after following the below process, I could able to update the field with null value. Below is the flow of my Logic app.
In my codeview
"body": {
"crc76_primarycontactid": "#{null}"
}
Results
Before updating
After updating

Related

Select nested json into columns/rows

I'm using PostgreSQL 13.6. I have a buttons json column on a table. The buttons columns contains an array of button settings, similar to, but not always like this. This is one of the more complex ones. There are multiple buttons in each json blob, so I need to loop over them.
[{
"label": "Submit",
"action": ["submit"]
}, {
"label": "New",
"action": ["new"]
}, {
"label": "Profile this",
"action": ["copyToOwn"],
"activeOn": {
"record": ["profile"],
"displayMode": ["Read Only"],
"existingOnly": true
}
}]
Here's a couple more examples:
[{"label":"Submit","action":"submit"}] --Single button
[{"label":"Reset","action":"reset"},{"label":"Search","action":"search"}] --Two buttons
[{"label":"Reset","action":["reset"],"activeOn":"profile"},{"label":"Search","action":["redirect"],"redirect":["url_alias"],"redirect_template":"/render/id"}] -- Two buttons with different settings
I want to make a new row in a buttons table for each button of each row. So label, action, active_on, record, display_mode, existing_only, redirect, and redirect_template would be columns.
The tables are like this
create table structure.button (
id integer not null
action text not null,
description text not null,...
create table structure.button_config (
button_id integer not null,
redirect_template text,
redirect text,
active_on text,
existing_only boolean,
record integer,...
So a row might look like
button table
id label action
1 Reset reset
button_config
button_id redirect_template redirect active_on ...
1 /render/id url_alias profile
This could be a function or a query. I have basically full access to the DB. I just cannot seem to figure out looping over json inside postgres.

How to handle null or Non required column in json in Azure Logic App

sample api url: https://jsonplaceholder.typicode.com/posts
title is not a mandatory field in received json. It may or may not be part of each record.
When this field is missing in record, #{items('For_each')['title']} this throws an exception.
I want the value of myVariable to set as 'N/A' in that case. How do i do this?
I make the assumption that this is an array and that you have a set schema in the HTTP trigger. If the schema is set, make sure you remove Title as a required field.
Using these asumptions you should be able to do the following with Coalesce()
If Title now is not present in the body of the HTTP request the Title will be equal to 'N/A'
Using postman to test, note, the result is backward as it is the first object sent in my array.
Cause you url data all have the title, so I test with When a HTTP request is recived trigger to get the json data.
In this situation the data could only be like this:
{
"userId": 1,
"id": 2,
"body": "xxxxx"
}
not like the below one:
{
"userId": 1,
"id": 2,
"title":,
"body": "xxxxxxxxx"
}
I test with the first one, it did show the error message: property 'title' doesn't exist,. So here is my solution, after the action Set variable, add an action to set the variable you want and set the action run after Set variable has failed like the below picture.
After configuration, if the title doesn't exist, it will be set as N/A as you want.
Hope this could help you, if this is not what you want or you have other questions, please let me know.

Adding a field mapping to 'base64Encode' an index field by calling REST endpoint not working: "A resource without a type name was found"

I'm trying to update a search index (using the Update Indexer) by sending a PUT request to https://searchservicename.search.windows.net/indexes/indexName?api-version=2017-11-11 and it's not working.
If I make the exact same request with the list of fields, the request works as expected and I receive a 200. As soon as I try to add fieldMappings as well, I get an error.
My Json I'm adding to the request as "application/json":
{
"name": "indexName",
"fields": [
<List of Valid Fields w/ Valid Types>
],
"fieldMappings": [
{
"sourceFieldName": "fieldName",
"targetFieldName": "fieldName",
"mappingFunction": {
"name": "base64Encode"
}
}
]
}
When calling the API, the error I'm getting is:
{Search request failed: {"error":{"code":"","message":"The request is invalid. Details: index : A resource without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\r\n"}}
I expect the request to return 200 and have the field mapping added.
The error I get seems to be related to the list of fields but as mentioned before, the request works as expected with the same body minus the field mappings.
Let me know if you need any other information from me - Thanks.
Field mappings should be added to an indexer, not an index. Based on your request, you are trying to update an index.

2sxc How to debug a query

I have created a view for a "details" page, and have set up a visual query to get the required item from a query string variable.
Testing the query works, and a single item is returned in the test:
{
"Default": [
{
"Title": "The Person",
"JobTitle": "CEO",
"Organization": "The Company",
etc (exactly what is expected)
}
]
}
This is piped to the Default input of the 2sxc Target, and running the test shows that 1 item is sent to the Target.
Now, when I actually execute the module, what I get is "No demo item exists for the selected template." which indicates that the data is not actually getting to the module.
I have selected the query as the data source for the view.
How to debug this?
You're running into a different problem: your view has a content-type defined, but no demo-item. In this scenario, it shows the message you see. So either say "no content-type" or give it a demo-item. Then the template is run.

Generate JSON schema

Im trying a setup a Microsoft flow. In short, I need to take JSON data retrieved from a device, and parse it so that i could reference it in the Flows below. In order to parse, i need to provide the JSON Schema to Flow. Microsoft Flow has an option to generate it from a sample payload (the results returned from the API call), but it's not generating it correctly. I'm hoping someone can help me. I need the correct JSON Schema.
The data returned from the API:
[
null,
[
{
"user_id": 2003,
"user_label": "Test1"
},
{
"user_id": 2004,
"user_label": "Test2"
}
]
]
Scheme generated in Flow from the above sample payload:
{
"type": "array",
"items": {}
}
I then tried to generate the Schema from just the data. That seemed to work, but when the Flow runs, I get a Json validation error.
Tried generating from just the data like this:
{
"user_id": 2003,
"user_label": "Test1"
}
This generated the scheme like this:
{
"type": "object",
"properties": {
"user_id": {
"type": "number"
},
"user_label": {
"type": "string"
}
}
}
So you have 2 things going on, the nested object array, and the null.
You'll need another Parse JSON after the first Parse JSON. And you'll want to filter out the null before the second Parse JSON.
It took me a while to figure out, but I hope this helps.
Start by adding the Parse JSON step to whatever step is outputting the JSON.
Now, filter the array, make sure you use the 'Expression' when comparing with null.
Add the second Parse JSON, you'll notice that you won't have the option to select the output "Item" of the Filter array step, so select 'Parse JSON' - Item for now (we will change this to use the output of the Filter JSON step in a moment)
The step should automatically change to an 'Apply to each'. In the Parse JSON 2, generate the schema with
[
{
"user_id": 2003,
"user_label": "Test1"
},
{
"user_id": 2004,
"user_label": "Test2"
}
]
Then, modify the 'Select an output from previous steps field' and change it (from the Body of the Parse JSON step) to the Body of the Filter Array step
Finally, add an action after Parse JSON 2 and select one of the fields in Parse JSON 2, this will automatically change that step to a nested Apply to each
You should end up with something like this:

Resources