Skriptbeispiel im Jitterbit App Builder - Ein Feld als XML zurückgeben
Dieses Plugin-Script gibt ein Feld Ihres Datenobjekts über den REST- Endpoint als XML zurück und macht es so für andere Anwendungen und Plattformen nutzbar. Beachten Sie die Konfigurationshinweise zur Implementierung dieses Plugins im App Builder.
Script
#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
/**
The format of the json produced by App Builder is:
{
items: [
{
"field1": "value",
"field2": "value",
"field3": "value",
...
}
...
]
}
This plugin is grabbing the FIRST item returned (["items"][0])
We then look for a particular field containing xml - in this case "xmlCode"
We then return this as the xml content - discarding the rest of the message
**/
// Read the response content
var message = await Response.Content.ReadAsStringAsync();
var jobject = JObject.Parse(message);
// This is likely always the same - the first item returned
var item = jobject["items"][0];
// Change xmlCode to match the name of the field in your object:
var xmlContent = item["xmlCode"].ToString();
// Return just the xmlContent
Response.Content = new StringContent(xmlContent, null, "application/xml");
Konfigurationshinweise
-
Verwenden Sie beim Konfigurieren des Plugins im App Builder die folgenden Werte:
- Name: ReturnXmlFromJson
- Beschreibung: Aus JSON zurückgegebenes XML auswählen und als reines XML zurückgeben
- Zweck: Ruhereaktion
-
Klicken Sie beim Konfigurieren des XMP- Endpoint im App Builder auf Edge Case-Einstellungen und setzen Sie den Wert Antwort des Endpoint Plugins auf ReturnXmlFromJson
-
Setzen Sie beim Konfigurieren des REST API Webdienstes den Wert Request Content Type auf JSON und den Response Content Type auf XML