Neu AmazonCustomJSON Werte in ein Datenbankfeld

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Guten Tag,

ist es möglich die Werte aus einer Amazonbestellung mit Custom Werten in das Datenbankfeld "SalesOrderPosition.Note" zu schreiben?
Kann man die u.g. Werte irgendwie in das "sonstige" Feld in dem Aufrag schreiben das entspricht dem Feld "SalesOrderPosition.Note"

Unser Code um die Daten von Amazon zu bekommen und in dem Auftrag anzuzeigen.

SQL:
"Anpassungsinformationen:" + "¶" +
"Farbe: " + JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:colorName",":") + "¶" +
"Schriftart: " + JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:fontFamily",":") + "¶" +
JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:name",":") + "¶" +
JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:text",":") + "¶" +
JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:name",":") + "¶" +
JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:text",":") + "¶" + "¶"
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Grundsätzlich scheint es Möglich zu sein die Funktion "JTL_GetJsonValue" in SQL zu übertragen wenn man diese Funktion in einem Workflow nutzen will.
SQL:
{% capture query -%}

JSON_VALUE(SalesOrderPosition.AmazonCustomJSON,'data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:name')

{% endcapture -%}

Infos findet man hier.
https://docs.microsoft.com/de-de/sql/t-sql/functions/json-value-transact-sql?view=sql-server-ver15

Kann mir jemand sagen ob das der richtige weg ist?
Kann ich die Amazon Daten aus der SQL Datenbank auslesen als Querry und dann in ein anderes Feld schreiben?
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Moin,
ich habe nun ein SQL Code geschrieben der die Amazon-Customization Daten aus der Datenbank richtig anzeigt:

SQL:
Select cArtNr, cName,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[0].fontFamily') AS Schriftart,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[0].colorName') AS Schriftfarbe,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[0].name') AS Feld1,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[0].text') AS Text1,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[1].name') AS Feld2,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[1].text') AS Text2,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[2].name') AS Feld3,
JSON_VALUE(REPLACE(cCustomJson,'.','_'),'$.data.orderCustomizationData[0].customizationInfo.version3_0.surfaces[0].areas[2].text') AS Text3
FROM dbo.pf_amazon_bestellungpos
WHERE cCustomJson like '{"%'

Leider kann ich diesen Code nicht als DirectQuery in einem Workflow einbauen da wohl wirklich nur uns ausnahmslos SELECT Anweisungen verstanden werden. Hier wird aber die SQL Funktion "JSON_VALUE" und "REPLACE" benötigt da sonst der JSON Sting nicht aufzulösen ist.

Infos zum einfügen in einen Workflow gibt es hier:

Komplexe Abfragen

Mein Workflow Code dazu wäre das... (hier die Version nur mit SQL Select ohne die o.g. Funktionen )
Code:
{% assign result = 'Select cArtNr, cName FROM dbo.pf_amazon_bestellungpos WHERE kAmazonBestellung = 73763' | DirectQuery -%}
{{ result }}
"{{ result.Query }}" lieferte {% if result.Fehlerhaft %}den Status {{ result.Fehler }}{% else %}keinen Fehler.{% endif %}
{% for item in result.Daten %}
ArtName: {{item.cName}}
ArtNr: {{item.cArtNr}}
Schriftart: 
Farbe:
Feld1:
Text1:
Feld2:
Text2:
Feld3:
Text3:
{% endfor -%}

Wenn man versucht die Query zu schreiben bekommt man einen Fehler da die " , " und " ' " in den Funktionen von SQL von JTL Wawi nicht richtig erkannt werden.

Ist es möglich irgendwie diese Daten aus dem SQL Server auszulesen und über einen Workflow von JTL in das HINWEIS Feld des Auftrages zu schreiben? Kennt sich jemand damit ein wenig besser aus?
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Hat geklappt:
ich musste allerdings einpaar Datenbanknamen anpassen. Unser SQL Server wollte es so haben.

Und mal wieder etwas mehr SQL gelernt

Code:
{% capture query %}
SELECT [dbo].[pf_amazon_bestellungpos].[cArtNr], [dbo].[pf_amazon_bestellungpos].cName,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].fontFamily') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].fontFamily') end as Schriftart,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].colorName') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].colorName') end as Schriftfarbe,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].name') end as Feld1,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[0].text') end as Text1,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[1].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[1].name') end as Feld2,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[1].areas[0].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[1].text') end as Text2,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[2].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[2].name') end as Feld3,
CASE WHEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[2].name') IS NOT NULL
THEN JSON_VALUE([dbo].[pf_amazon_bestellungpos].[cCustomJson],'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[2].text') end as Text3
FROM tBestellung
JOIN tbestellpos on tBestellung_kbestellung = tBestellung.kBestellung
JOIN pf_amazon_bestellungpos on [dbo].[pf_amazon_bestellungpos].kAmazonBestellungPos = tbestellpos.kAmazonBestellungPos
WHERE cBestellNr = '{{Vorgang.Stammdaten.Auftragsnummer | SqlExcape}}'
{% endcapture -%}
{% assign result = query | DirectQuery -%}
{% if  result.Fehlerhaft-%}
{{result.Fehler}}
{% else -%}
{% for row in result.Daten -%}
Bezeichnung: {{row.cName}}
Name: {{row.cArtNr}}
Schriftart: {{row.Schriftart}}
Farbe: {{row.Schriftfarbe}}
Feld1: {{row.Feld1}}
Text1: {{row.Text1}}
Feld2: {{row.Feld2}}
Text2: {{row.Text2}}
Feld3: {{row.Feld3}}
Text3: {{row.Text3}}


{% endfor -%}
{% endif -%}
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Hallo,

wir haben jetzt noch ein Problem mit den Anzeigen der Daten in den Vorlagen für Auftrag und Rechnung hier sollen die Daten in der jeweiligen Artikelposition angezeigt werden:

Problem ist dabei das wir 2 Zeilen oder auch 3 Zeilen haben in dem JSON die wir auslesen wollen. Wir haben in den Rechnungsvorlagen nun alle drei Zeilen eingebaut. Wenn die Zeilen alle genutzt werden wir alle korrekt angezeigt wenn aber die dritte Zeile nicht genutzt wird gibt es eine Fehlermeldung der Funktion die dann in die Vorlage geschrieben wird.

JTL_GetJsonValue(SalesOrderPosition.AmazonCustomJSON,"data:eek:rderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[2]:text",":")
Fehler:
Error: Der Index lag außerhalb des Bereichs. Er darf nicht negativ und kleiner als die Sammlung sein.

Wenn wir versuchen die Felder über JTL_DirectQuery in der Vorlage abfragen wollen bekommen wir ein Problem mit dem JSON da dieser ein Wert enthält der mit " " oder ' ' aus geklammert werden muss dieses kann aber die Funktion in der Vorlage nicht verarbeiten

JSON_VALUE(cCustomJson,'$.data.orderCustomizationData[0].customizationInfo."version3.0".surfaces[0].areas[2].text') -> Dieser Wert kann nicht vom Editor gelesen werden und wird nicht in die Vorlage übernommen
JSON_VALUE(cCustomJson,'$.data.orderCustomizationData[0].customizationInfo.'version3.0'.surfaces[0].areas[2].text') -> Falsche Syntax bei Version3.0
JSON_VALUE(cCustomJson,'$.data.orderCustomizationData[0].customizationInfo.version3.0.surfaces[0].areas[2].text') -> Fehler wegen dem "." in Version3.0
Ich komme hier nicht weiter wie bekomme ich die Werte der Bestellung von dem JSON in die Auftrags und Rechnungsvorlage wenn mal zwei und mal drei werte angezeigt werden sollen?
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Ich habe eine Lösung mit Cond(), StartsWith() "Error" und JTL_GetJsonValue gefunden für die Rechnungsvorlage / Auftragsvorlage und für den Workflow habe ich ebenso die SQL query ergänzt.

Sobald die Lösungen implementiert sind werde ich diese hier teilen.

Eigentlich müsste ja jeder der Amazon Custom nutzt die selben Probleme haben und könnte diese Lösung nutzen.

Gruß
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Hier wäre für die Bestellposition der Code:

Code:
InvoicePosition.Name + "¶" +
Cond(JTL_DirectQuery ("SELECT cHAN FROM tArtikel WHERE tArtikel.kArtikel = '"+ToString$(InvoicePosition.ProductInternalId)+"'") == "", "", "" +"HAN: " + JTL_DirectQuery ("SELECT cHAN FROM tArtikel WHERE tArtikel.kArtikel = '"+ToString$(InvoicePosition.ProductInternalId)+"'")) + "¶" +

Cond(
IsNullOrEmpty(
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:colorName",":")),
" ",
Cond(
StartsWith(JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:colorName",":"),'Error: Der'),
" ",
 'Anpassungsinformationen:' + '¶' + 'Farbe: ' + JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:colorName",":")+ "¶"
)) +

Cond(
IsNullOrEmpty(
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:fontFamily",":")),
" ",
Cond(
StartsWith(JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:fontFamily",":"),'Error: Der'),
" ",
 'Schriftart: ' + JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:fontFamily",":")+ "¶"
)) +

Cond(
IsNullOrEmpty(
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:text",":")),
" ",
Cond(
StartsWith(JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:text",":"),'Error: Der'),
" ",
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:name",":") + "¶" + JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[0]:text",":")+ "¶"
)) +

Cond(
IsNullOrEmpty(
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:text",":")),
" ",
Cond(
StartsWith(JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:text",":"),'Error: Der'),
" ",
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:name",":") + "¶" + JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[1]:text",":")+ "¶"
)) +

Cond(
IsNullOrEmpty(
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[2]:text",":")),
" ",
Cond(
StartsWith(JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[2]:text",":"),'Error: Der'),
" ",
JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[2]:name",":") + "¶" + JTL_GetJsonValue(InvoicePosition.AmazonCustomJSON,"data:orderCustomizationData[0]:customizationInfo:version3.0:surfaces[0]:areas[2]:text",":")+ "¶"
))

Wenn man verschiedene AmazonCustoms nutzt mit mal 2 oder mal 3 Zeilen dann kann man es so umsetzten das die Werde in der Rechnung angezeigt werden.
 

AlexD

Aktives Mitglied
25. November 2016
52
4
Wir sind da schon echt weit gekommen.

Wir hatten das Projekt das wir die Werte in die Rechnung etc übernehmen wollten und in das "Sonstige" Feld in den Vorgang schreiben.

Was genau ist den ihr Projekt? Vielleicht kann man sich ja unter stützen.

Wir vertreiben amtl. Kennzeichen, als auch Fun-Schilder (u. a. auch bunte Kennzeichen mit Namen oder "Parkplatz") - hier gibt der Kunde seinen Wunschdruck bei Amazon ein und wir prägen es entsprechend.

Wäre es vllt möglich die Lösungen zu veröffentlich? Das jeder sich das Ganze noch entsprechend umbauen muss, ist logisch, da die Datensätze unterschiedliche Umfänge haben.
 

kornwestheimer

Sehr aktives Mitglied
8. September 2016
195
25
Moin,

ja klar die "Lösungen" bzw. unsere Ansätze kann ich gerne Teilen.

Die frage wäre nun was genau haben Sie vor? Dann kann ich hier mal unseren Code posten und eine kurze Beschreibung. Vielleicht kann man zusammen das alle noch weiter verbessern.

Wir haben eine Lösung für:

Übertragen in das Sonstige Feld der Auftrages / Rechnung etc.
Anzeige der Daten in der Rechnung / Auftrag bei der Artikelposition
 
Ähnliche Themen
Titel Forum Antworten Datum
Beantwortet Werte eigener Kundenfelder im Template anzeigen Allgemeine Fragen zu JTL-Shop 0
cInet - Welche Werte erlaubt? JTL-Wawi 1.8 1
Stückliste zeigt falsche Werte JTL-Wawi 1.8 0
Merkmal ohne angelegte Werte mit Maßeinheit JTL-Wawi 1.8 5
Neu Amazon Prime - DHL Versandlabel kann nicht gedruckt werden "Ein Prime Versandlabel wurde nicht gekauft, da kein verfügbares gefunden wurde." JTL-ShippingLabels - Fehler und Bugs 0
Kann ich eine email an die Wawi senden durch die dann ein neuer Auftrag generiert wird? (Daten müssen händisch vervollständigt werden...) JTL-Wawi 1.8 2
Gelöst WMS 1.8.11.2 friert beim Starten ein JTL-WMS / JTL-Packtisch+ - Fehler und Bugs 5
Neu jtl wawi Versanddatenexport Originalmeldung: In der Sendung trat mindestens ein harter Fehler auf. Code: 1101 Schnittstellen Import / Export 2
In Bearbeitung Umzug mit einer Kasse auf ein neues Gerät Allgemeine Fragen zu JTL-POS 2
Neu Exportvorlage Facebook: Mehr als ein Bild übergeben? Allgemeine Fragen zu JTL-Shop 0
Neu Woran kann es liegen, dass ein neu erstellter Connector-Verkaufskanal nicht in der Statusliste des Workers vorkommt? Shopify-Connector 2
Neu Wer kann bei uns ein EcoDMS einrichten? Dienstleistung, Jobs und Ähnliches 16
Neu ein email formular auf startseite einbinden Allgemeine Fragen zu JTL-Shop 0
In Bearbeitung Mehrere Karten/Buchnungskonten aber nur ein Karten-Terminal (Ethernet) Allgemeine Fragen zu JTL-POS 4
Angebote ohne Auftrag, die wieder auftauchen und ein Auftrag haben, der sogar versendet wurde. JTL-Wawi 1.8 1
Neu Gmail stuft uns als SPAM ein User helfen Usern - Fragen zu JTL-Wawi 11
Neu Keine Übersicht mehr auf welcher Plattform ein Artikel eingestellt ist. JTL-Wawi - Fehler und Bugs 0
Neu jtl datenbank warnung - ein formular hat mehr als 1000 felder in tkunde des Shops Allgemeine Fragen zu JTL-Shop 0
Neu Wawi läuft, aber ein Rechner hat den Pfad zur Datenbank verloren, Mandant kann nicht ausgewählt werden User helfen Usern - Fragen zu JTL-Wawi 3

Ähnliche Themen