Проблемы с обновлением столбца поиска Dataverse с использованием Java 8JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Проблемы с обновлением столбца поиска Dataverse с использованием Java 8

Сообщение Anonymous »

У меня возникла проблема: я не могу обновить столбец поиска с помощью Java. Я протестировал несколько вариантов, но ничего не работало. Ниже приведен код (тот же код, который я использую для других типов столбцов, и он там работает):
public static void main(String[] args) throws Exception {

DataverseController.updateColumnEMailMVPLookup(
"/tableWithDataForInput(GUID_of_row)",
"GUID_row_id_in_table_for_change",
token,
"https://myOrganiztion.crm4.dynamics.com/api/data/v9.2/",
"uniqa_mailtype"
);
}

public static void updateColumnEMailMVPLookup(
String value,
String row_id,
String token,
String url,
String columnForEditting
) throws IOException {

Map mapUpdate = new HashMap();

if ((value != null) && (value.trim().length() > 0)) {
mapUpdate.put(columnForEditting + "@odata.bind", "/" + value);
}

JSONObject obj = new JSONObject(mapUpdate);
String jsonString = obj.toString();

String uri = url + "nameTableForCorrect(" + row_id + ")";

URL urlFinal = new URL(uri);
HttpURLConnection httpURLConnection = (HttpURLConnection) urlFinal.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("PUT"); // PATCH back error
httpURLConnection.setRequestProperty("Authorization", "Bearer " + token);
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");

try (OutputStream outputStream = httpURLConnection.getOutputStream()) {
outputStream.write(jsonString.getBytes());
outputStream.flush();
}

int responseCode = httpURLConnection.getResponseCode();
StringBuilder response = new StringBuilder();

if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
// Successful update, no content expected in response
System.out.println("Update successful.");
} else {
// Read the error response
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
response.append(line);
}
}
System.err.println("Update failed: " + responseCode + " " + httpURLConnection.getResponseMessage());
System.err.println("Error response: " + response.toString());
String enf = "";
}
}

Если кто-нибудь сможет помочь с этим, я буду очень благодарен.
Я очень старался. На самом деле проблема в том, что он не поддерживает способ написания столбца поиска.
Ошибка:
Update failed: 400 Bad Request
Error response: {"error":{"code":"0x80048d19","message":"Error identified in Payload provided by the user for Entity :'', For more information on this error please follow this help link https://go.microsoft.com/fwlink/?linkid=2195293 ----> InnerException : Microsoft.OData.ODataException: An undeclared property 'uniqa_mailtype' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadUndeclaredProperty(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean propertyWithValue)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithoutValue(IODataJsonLightReaderResourceState resourceState, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.c__DisplayClass9_0.b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at Microsoft.Crm.Extensibility.CrmODataEntityDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)."}}


Подробнее здесь: https://stackoverflow.com/questions/788 ... ing-java-8
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»