0

Per API in eine Untertabelle / Verknüpfte Tabelle schreiben

Kann man via API in eine Untertabelle / Verknüpfte Tabelle schreiben sodass es sofort sichtbar ist.

Sonst muss man immer auf das + Symbol gehen und eine Zeile einfügen.

Kann da jemand helfen?

lg

Ben

10 Antworten

null
    • Leonid_Semik
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Hallo Ben,

    Wenn du den Inhalt des Textfeldes in einen neuen Datensatz der Untertabelle schreiben möchtest, kann man das mit einem Button machen:

    ...

    let my:=this;

    let myContent:=HAUPTTABELLENTEXTFELD;

    let new:=create UNTERTABELLE;

    new.HAUPTTABELLE:=my;

    new.UNTERTABELLENTEXTFELD:=myContent

    ...

    Leo

    • Benjamin_Kromer
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Hallo Leo,

    das ist der absolute Hammer! Vielen Dank dafür Leo! Das konnten die Profis von Ninox mir nicht sagen. ;)

     

    lg

    Ben

    • Benjamin_Kromer
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Hallo Leo,

    Folgefrage: Ich rufe über die API meines MIS-Systems Kundendaten ab.

    Im ersten Durchgang hole ich die Firmen Infos und im zweiten Durchgang (in einem zweiten http Aufruf) die Personen der Firmen. Jetzt möchte ich dass in der Haupttabelle alle Firmen stehen und dass jede Firma eine Untertabelle hat mit Ihren Personen.

    Aktuell sieht mein Script so aus:

    let page := 0;
    while lenjsonpage > 0 do
    page := page + 1;
    jsonpage := page;
    let re := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    lenjsonpage := cnt(re.result);
    for nameorcompany in range(0, cnt(re.result)) do
    let newrecord := (create 'Kundendatenbank aus Keyline');
    let companyid := text(item(re.result, nameorcompany).id);
    "ID WIRD FÜR DEN NÄCHSTEN API CALL ALS VARIABLE BENÖTIGT - ITEM OBJEKTE FUNKTIONIEREN NICHT!";
    newrecord.(id := text(item(re.result, nameorcompany).id));
    newrecord.('Name oder Firma' := text(item(re.result, nameorcompany).name));
    newrecord.(tax_identifier := text(item(re.result, nameorcompany).tax_identifier));
    newrecord.(email := text(item(re.result, nameorcompany).email));
    newrecord.(reference := text(item(re.result, nameorcompany).reference));
    newrecord.(debitor_identifier := text(item(re.result, nameorcompany).debitor_identifier));
    newrecord.(creditor_identifier := text(item(re.result, nameorcompany).creditor_identifier));
    newrecord.(preferred_locale := text(item(re.result, nameorcompany).preferred_locale));
    newrecord.(credit_limit := text(item(re.result, nameorcompany).credit_limit));
    newrecord.(created_at := text(item(re.result, nameorcompany).created_at));
    newrecord.(updated_at := text(item(re.result, nameorcompany).updated_at));
    " AB HIER WERDEN DIE PERSONEN EINER ORGANISATION ABGEFRAGT";
    let repersons := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations/" + companyid + "/people", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    for person in range(0, cnt(repersons.result)) do
    let my := this;
    let personid := text(item(repersons.result, person).id);
    let personname := text(item(repersons.result, person).name);
    let new := (create UNTERTABELLE);
    new.('Kundendatenbank aus Keyline' := my);
    new.('Keyline ID' := personid);
    new.(Name := personname)
    end
    end;
    lenjsonpage := cnt(re.result);
    test := test + text(re.result)
    end

    Das bewirkt dass die Untertabelle nur im ersten Datensatz der Haupttabelle vorhanden sind und zwar alle Personen aller Firmen.

    Hoffe es einigermaßen verständlich gemacht zu haben.

    Wäre cool wenn du hier nochmal helfen könntest. ;)

    lg

    Ben

    • Benjamin_Kromer
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Meine Vermutung wäre dass man der Variable "my" den jeweils neuen Firmendatensatz gibt. 

    Etwa so: let my := select 'Kundendatenbank aus Keyline' where text('id') = text(companyid); 

    Aber das funktioniert nicht...

    • Ninox-Professional
    • planoxpro
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Hallo, vielleicht irre ich mich, aber sollte die Verknüpfung des Personendatensatzes mit dem der Firma nicht über "newrecord" erfolgen? Denn diese Variable enthält doch die Ninox-ID des übergeordneten Datensatzes. Oder sehe ich das falsch?

     

    new.('Kundendatenbank aus Keyline' := newrecord);

    • Leonid_Semik
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Hallo Ben,

    Ich würde hier statt while normale for Schleifen nehemen. In deinem Skript beziest du alle Personen zu den Aktuellen Datensatz außerhalb der Schleife (let my := this;.........new.('Kundendatenbank aus Keyline' := my). Du solltest hier aber newrecord einfügen, den das ist die Aktuelle Firma innerhalb der Schleife.(new.('Kundendatenbank aus Keyline' := newrecord)

    ...

    let re := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    for i in re.result do
    let newrecord := (create 'Kundendatenbank aus Keyline');
    newrecord.(id := text(i.id));
    newrecord.('Name oder Firma' := text(i.name));
    newrecord.(tax_identifier := text(i.tax_identifier));
    newrecord.(email := text(i.email));
    newrecord.(reference := text(i.reference));
    newrecord.(debitor_identifier := text(i.debitor_identifier));
    newrecord.(creditor_identifier := text(i.creditor_identifier));
    newrecord.(preferred_locale := text(i.preferred_locale));
    newrecord.(credit_limit := text(i.credit_limit));
    newrecord.(created_at := text(i.created_at));
    newrecord.(updated_at := text(i.updated_at));
    " AB HIER WERDEN DIE PERSONEN EINER ORGANISATION ABGEFRAGT";
    let repersons := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations/" + text(i.id) + "/people", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    for j in repersons.result do
    let new := (create UNTERTABELLE);
    new.'Kundendatenbank aus Keyline' := newrecord);
    new.('Keyline ID' := text(j.id));
    new.(Name := text(j.name)
    end
    end

    ...

    Leo

    • Leonid_Semik
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Wenn zwei Personen es so meinen, dann stimmt es auch meistens.

    • Benjamin_Kromer
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Sehr gut, das funktioniert perfekt! Jetzt muss ich nur noch was schreiben damit wenn man zweimal draufdrückt keine Duplikate erstellt werden sondern nur neue Datensätze erstellt werden und geänderte geupdated werden und dass natürlich für Haupt und Untertabelle.... :-/

    • Leonid_Semik
    • vor 4 Jahren
    • Gemeldet - anzeigen

    let re := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    for i in re.result do
    if cnt(select 'Kundendatenbank aus Keyline' where id=text(i.id))=0 then

    let myrecord := (create 'Kundendatenbank aus Keyline');

    myrecord.(id := text(i.id)) else

    let myrecord:=first(select 'Kundendatenbank aus Keyline' where id=text(i.id))
    end;
    myrecord.('Name oder Firma' := text(i.name));
    myrecord.(tax_identifier := text(i.tax_identifier));
    myrecord.(email := text(i.email));
    myrecord.(reference := text(i.reference));
    myrecord.(debitor_identifier := text(i.debitor_identifier));
    myrecord.(creditor_identifier := text(i.creditor_identifier));
    myrecord.(preferred_locale := text(i.preferred_locale));
    myrecord.(credit_limit := text(i.credit_limit));
    myrecord.(created_at := text(i.created_at));
    myrecord.(updated_at := text(i.updated_at));
    " AB HIER WERDEN DIE PERSONEN EINER ORGANISATION ABGEFRAGT";
    let repersons := do as server
    http("GET", "https://app.keyline-mis.com/api/v2/customer_relations/organizations/" + text(i.id) + "/people", {
    Authorization: "Bearer " + keylineAdminKey(),
    'Content-Type': "application/json",
    'X-Keyline-Requested-Page': text(page)
    }, {})
    end;
    for j in repersons.result do
    if cnt(myrecord.UNTERTABELLE[id=text(j.id)])=0 then
    let myperson := (create UNTERTABELLE);
    new.'Kundendatenbank aus Keyline' := myrecord;
    new.('Keyline ID' := text(j.id))
    else
    let myperson:=first(myrecord.UNTERTABELLE[id=text(j.id)])
    end;
    myperson.Name := text(j.name)
    end
    end;

    • Benjamin_Kromer
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Das funktioniert nicht ganz... wenn nur Personen dazu kommen werden die nicht erstellt.

    Ich bau mal noch ein else ein..

Content aside

  • vor 4 JahrenZuletzt aktiv
  • 10Antworten
  • 2926Ansichten