Ingevulde webformulieren automatisch doorzetten naar Exact Online met Power Automate

Met Invantive Cloud is het eenvoudig mogelijk om ingevulde webformulieren op basis van Microsoft Forms automatisch te verwerken in Exact Online.

In dit voorbeeld leer je hoe voor onderstaand contactformulier automatisch het bedrijf met contactpersoon opgevoerd of bijgewerkt kan worden, terwijl een taak voor een medewerker wordt opgevoerd.

Meer informatie over het gebruik van Power Automate met Exact Online, en de verschillen met de mogelijkheden van Exact Online Premium is te lezen in Gebruik Power Automate met Exact Online.

Resultaat

Het invullen van het webformulier met:

  • Vraag: hoeveel sinasappels passen er in de container van type 3600 Turbo? En hoeveel ping-pongballen?
  • Voornaam: John
  • Achternaam: Doe
  • Bedrijfsnaam: ACME Corp.
  • E-mailadres: john.doe@acme.com
  • Telefoonnummer +31880026500

leidt tot de volgende resultaten.

Power Automate

image

Merk op dat de verwerkingsduur afhankelijk is van het aantal nog beschikbare API-calls per minuut op Exact Online.

Exact Online bedrijf

Het bedrijf “ACME Corp.” wordt toegevoegd:

Exact Online contactpersoon

De contactpersoon is toegevoegd aan het bedrijf:

Exact Online taak

Een taak is aangemaakt met de vraag:

Inrichting

Om de ingevulde waardes vanuit Microsoft Forms te laden in Exact Online als nieuw/bijgewerkt bedrijf, nieuwe/bijgewerkte contactpersoon en nieuwe taak zijn instellingen nodig in Power Automate en Invantive Cloud.

Power Automate Stroom

Binnen Power Automate dient een stroom gedefinieerd te worden:

image

Het formulier in Microsoft Forms dient opgegeven te worden bij de eerste stap:

image

En herhaald bij de tweede stap, samen met de reactie-ID:

image

Tenslotte dienen de antwoorden doorgegeven te worden aan Invantive App Online als verwerker van de applicatie binnen Invantive Cloud na authenticatie:

Merk op dat de “body” JSON samenstelt voor de antwoorden.

Invantive Cloud Exact Online-database

Zorg dat een Exact Online-database voorhanden is. Indien niet, maak een Exact Online-database aan zoals beschreven en getoond op Verbind Power BI met Exact Online.

Invantive Cloud applicatiemodule

De daadwerkelijke logica gebeurt door een applicatiemodule:

De URL voor de laatste stap in Power Automate kan opgevraagd worden door de applicatie te starten met de gewenste database, en bij het kaartje van de applicatiemodule rechtsonder te kiezen voor “Kopieer link”.

De gebruikte Invantive PSQL-code beschrijft de logica:

declare
  l_payload    clob;
  l_account_id guid;
  l_contact_id guid;
begin
  --
  -- Choose Exact Online company.
  --
  use 102673@eol;
  --
  -- Retrieve payload.
  --
  l_payload := cloud_http.get_request_body_text();
  --
  -- Parse and process:
  --
  -- 1. Create or update existing company.
  -- 2. Add or update contact to company.
  -- 3. Add task with request.
  --
  -- Note the use of "for". This allows multiple requests to be processed also
  -- for bulk loading.
  --
  for r
  in
  ( select *
    from   jsontable
           ( ''
             passing l_payload
             columns vraag      varchar2 path 'vraag'
             ,       voornaam   varchar2 path 'voornaam'
             ,       achternaam varchar2 path 'achternaam'
             ,       bedrijf    varchar2 path 'bedrijf'
             ,       email      varchar2 path 'email'
             ,       telefoon   varchar2 path 'telefoon'
             ,       verzoekid  varchar2 path 'verzoekid'
           )     
  )
  loop
    --
    -- 1. Create or update existing company.
    --
    select min(act.id)
    into   l_account_id
    from   ExactOnlineREST..Accounts@eol act
    where  act.name = r.bedrijf
    ;
    if l_account_id is not null
    then
      dbms_output.put_line('Company exists. Update it.');
      update ExactOnlineREST..Accounts@eol
      set    remarks = remarks || chr(13) || chr(10) || 'Updated on ' || to_char(sysdateutc)
      where  id = l_account_id
      ;
    else
      dbms_output.put_line('Company does not exist. Create it.');
      insert into ExactOnlineREST..Accounts
      ( name
      )
      values 
      ( r.bedrijf
      );
      select min(act.id)
      into   l_account_id
      from   ExactOnlineREST..Accounts@eol act
      where  act.name = r.bedrijf
      ;
    end if;
    --
    -- 2. Add or update contact to company.
    --
    -- The use of "if exists ( select ...)" would be shorter in
    -- code, but is not efficient since 
    -- the code will also relate the new task to the (new or existing) contact.
    --
    select min(ctt.id)
    into   l_contact_id
    from   ExactOnlineREST..Contacts@eol ctt
    where  Account = l_account_id
    and    Email   = r.email
    ;
    if l_contact_id is not null
    then
      dbms_output.put_line('Contact exists. Update it.');
      update ExactOnlineREST..Contacts@eol
      set    firstname = coalesce(r.voornaam, firstname)
      ,      lastname  = coalesce(r.achternaam, lastname)
      ,      phone     = coalesce(r.telefoon, phone)
      ,      notes = notes || chr(13) || chr(10) || 'Updated on ' || to_char(sysdateutc)
      where  id = l_contact_id
      ;
    else
      dbms_output.put_line('Contact does not exist. Create it.');
      insert into ExactOnlineREST..Contacts@eol
      ( account
      , firstname
      , lastname
      , email
      , phone
      )
      values
      ( l_account_id
      , r.voornaam
      , r.achternaam
      , r.email
      , r.telefoon
      );
      select min(ctt.id)
      into   l_contact_id
      from   ExactOnlineREST..Contacts@eol ctt
      where  Account = l_account_id
      and    Email   = r.email
      ;
    end if;
    --
    -- 3. Add task with request.
    --
    insert into ExactOnlineREST..tasks@eol
    ( ActionDate
    , Contact
    , Description
    , Notes
    )
    values
    ( trunc(sysdateutc) + 7
    , l_contact_id
    , 'Vraag van ' || r.voornaam || ' ' || r.achternaam || ' (' || r.email || ', ' || r.telefoon || ')'
    , r.vraag
    );
  end loop;
end;

Super vet dat dit nu mogelijk is! De lastigste stap blijft denk ik de PSQL-code schrijven. Tijd voor ChatGPT die helpt met PSQL schrijven? :stuck_out_tongue_winking_eye:

Dat is altijd te proberen! PSQL is sterk gelijkend op SQL/PSM - Wikipedia en PL/SQL. De grammatica is te vinden op Invantive UniversalSQL Grammar 23.0.

Een voorbeeld:

Een meer correcte implementatie zou zijn:

create or replace procedure PrintTotalAmount
is
  l_bedrag number;
begin
  select sum(bedrag)
  into   l_bedrag
  from   transacties
  ;
  dbms_output.put_line(l_bedrag);
end;

Deze is vrijwel identiek aan de implementatie in Oracle PL/SQL die voorgesteld wordt door ChatGPT:

1 like