Exemplo de script no Jitterbit App Builder - Retornar um campo como XML
Este script de exemplo de Plugin retornará um campo no seu objeto de dados por meio do endpoint REST como XML, tornando-o consumível por outros aplicativos e plataformas. Veja as Notas de configuração para implementar este Plugin no App Builder.
Exemplo de 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");
Notas de configuração
-
Ao configurar o Plugin no App Builder, use os seguintes valores:
- Nome: ReturnXmlFromJson
- Descrição: Selecione o xml retornado de dentro do json e retorne apenas como xml
- Objetivo: Resposta de repouso
-
Ao configurar o XMP Endpoint no App Builder, clique em Edge Case Settings e defina o valor Endpoint Plugin Response como ReturnXmlFromJson
-
Ao configurar o REST API Web Service, defina o valor Request Content Type como JSON e Response Content Type como XML