Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

Sommaire

Introduction

Ce document décrit la création de webhooks spécifiques.

Avant de créer vos propres webhooks, il est conseillé de lire l’ensemble des documents présents dans le chapitre WebHooks.

Et tout particulièrement de bien comprendre le document sur les Surcharges.

Déclaration webhooks

Dans Divalto weavy Studio : Outils > Gérer les webhooks

Webhook

Le webhook ne nécessite aucune authentification mais doit être lié à un compte API public.

...

URL : Url qui permettra d’appeler le webhook

Process

C’est l'équivalent du webhook, mais le process nécessite une authentification préalable avec un compte utilisateur valide.

...

URL : Url qui permettra d’appeler le process

Présentation

Lors de la création d’un nouveau webhook, cinq scripts sont obligatoires.

...

Le code du script devra être de la forme : {Prefix}_WebhookRules_{entityname}.

Script de surcharge de règles : Il est obligatoire même pour un webhook spécifique.

...

Vous pouvez vous contenter de la trame de base, vu que vos règles seront déjà dans le script de règles.

Créer webhook sur une table standard

Création d’un nouveau webhook sur la table standard “sw_data_supplier” qui contient des champs spécifiques en surcharge FINAL.

On peut voir également que le champ “final_suppliercategory_ID” s’appuie sur une table spécique spécifique “sw_data_final_suppliercategory”.

...

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_supplier

...

languagenone

...

Vu qu’il s’agit d’un webhook entièrement spécifique, on aurait pu laisser uniquement le squelette de “FINAL_WebhookDefinitionOverload_supplier“ et mettre le code nécessaire au fonctionnement directement dans “FINAL_WebhookDefinition_supplier“.

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_supplier

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'simpleFieldsList': 'CodeSupplier,label,city',
    'extendedFieldsListToExclude': '',
    'relatedTablesCount': 2,
    'relatedTables': [ 'final_customer_ID', 'final_suppliercategory_ID' ],
    'authorizedTables': [ {'tableName':'supplier'}, {'tableName':'final_supplieraddress'}, {'tableName':'product'} ],
    'cascadeDeleteTables': [ {'tableName':'final_supplieraddress'} ],
    'fieldsList': {
      'final_customer_ID': {
        'targetTableName': 'sw_data_customer',
        'targetFieldName': 'name'
      },
      'final_suppliercategory_ID': {
        'canGetDefinitionList': 1,
        'definitionLabelFieldName': 'final_label'
      }
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Script de règles : FINAL_WebhookRules_supplier

Il s’agit ici uniquement du squelette nécessaire au bon fonctionnement car nous nous n’avons pas implémenté de règle métier dans notre exemple.

Bloc de code
languagenone
// FINAL_WebhookRules_supplier

code      = TRANSLATE( "<varscript>arg1</varscript>" )
verb      = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput = TRANSLATE( "<varscript>arg3</varscript>" )

tableName               = "supplier"
entity                  = "supplier"
internalcode            = ""
codeTableName           = TRANSLATE( "code<varscript>tableName</varscript>" )
codeEntityName          = TRANSLATE( "code<varscript>entity</varscript>" )
internalcodeEntityName  = TRANSLATE( "internalcode<varscript>entity</varscript>" )
scriptOverload          = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" )

jsonResponse                        = DOCUMENT_CREATE_DOCUMENT()
ruleFields                          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" )
ruleOverloadFields                  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" )
ruleFieldsAdditionalTables          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" )
ruleOverloadFieldsAdditionalTables  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" )

// STANDARD RULES

IF( EQUALS( verb, "PUT" ) )THEN
  
  IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "0" )
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" )
    
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
    
  ENDIF
    
  jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity )
  VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput )
  
  
  IF ((LEN( code ) == 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THEN
    
    code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" )
    
  ENDIF
  
  IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" ) ) THEN
    
    internalcode = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" )
    
  ENDIF
  
  row_ID  = CALL_SCRIPT( "Func_GetIDFromCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>" )
  
ENDIF

// Rule overload
ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields )

IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
  
  response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" )
      
  IF( EQUALS( response, "0" ) )THEN
    
    IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
      
      errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage )

    ELSE
      
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" )
      
    ENDIF
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", response )
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
  
  ENDIF

ENDIF

DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "1" )
response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

...

Pour la mise à jour de “sw_data_final_supplieraddress“, une description est donnée dans le chapitre sur la création d’un webhook sur une table spécifique.

Pour l’affiche des données liées dans “sw_data_final_suppliercategory“, il faut donc au minimum également ajouter les deux scripts de définition de cette table.

Script de définition : FINAL_WebhookDefinition_final_suppliercategory :

Bloc de code
languagenone
 // FINAL_WebhookDefinition_final_suppliercategory
// Webhook definition
tableName             = "final_suppliercategory"
specificOverload      = CALL_SCRIPT( "FINAL_WebhookDefinitionOverload_<varscript>tableName</varscript>" )
tableSchema           = DB_GET_TABLEINFO( "sw_data_<varscript>tableName</varscript>" )
tableSchemaDocument   = DOCUMENT_CREATE_FROM_JSON( tableSchema )
languageCode          = VARGET_SHELL( "languageCode", "WebhookDefinition" )
authorizedTables      = TRANSLATE( "[{'tableName':'<varscript>tableName</varscript>'}]" )

JSONFieldsDefinition = TRANSLATE( "
  { 
    'languageCode': '<varscript>languageCode</varscript>',
    'strictFilterMode': 1,
    'relatedTablesCount': 0,
    'relatedTables': [ ],
    'authorizedTables': <varscript>authorizedTables</varscript>,
    'simpleFieldsList': 'CodeSupplier,label',
    'extendedFieldsListToExclude': '',
    'defaultFilters': [
     
    ],
    'strictFilters': [
      
    ],
    'strictOrderBy': [
    
    ],
    'outOfMainTableFields': [
      
    ],
    'standardOverload': {
      
    },
    'specificOverload':
    <varscript>specificOverload</varscript>,
    'simpleFields': [],
    'extendedFields': [],
    'strictFilterFields': [],
    'defaultFilterFields': [],
    'strictOrderByFields': []
  }
" )

INCLUDE( "FuncWebhook_BuildDefinition" )

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_final_suppliercategory :

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_suppliercategory

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'fieldsList': {

    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Créer webhook sur une table

...

standard si scripts déjà existants

Création d’un nouveau webhook sur la table spécifique standard “sw_data_final_supplieraddress”symptom”.

Dictionnaire :

...

FINAL_WebhookSupplierAddress

FINAL_WebhookDefinition_final_supplieraddress

FINAL_WebhookDefinitionOverload_final_supplieraddress

FINAL_WebhookRules_final_supplieraddress

FINAL_WebhookRulesOverload_final_supplieraddress

Compléter webhook existant

FINAL_WebhookDefinition_interventionoperationrange

FINAL_WebhookDefinition_interventionoperationtypeScript d’entrée : FINAL_WebhookSymptom

Bloc de code
languagenone
tableName   = "symptom"
entityName  = "symptom"

INCLUDE( "FuncWebhook_BuildEndpoint" )

Script de définition : WebhookDefinition_symptom

Le script de définition “WebhookDefinition_symptom“ existe déjà en standard. Donc on y touche pas.

Script de surcharge de définition : WebhookDefinitionOverload_symptom

Le script de surcharge de définition “WebhookDefinitionOverload_symptom“ est déjà prévu en standard. Il suffit donc de surcharger ce script si besoin.

Bloc de code
languagenone
// WebhookDefinitionOverload_symptom
 
languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'relatedTablesCount': 3,
    'relatedTables': [ 'equipmenttype_ID', 'equipmentkind_ID', 'symptom_ID_parent' ],
    'authorizedTables': [{'tableName':'symptom'}, {'tableName':'symptomauthorization'}],
    'cascadeDeleteTables': [ {'tableName':'symptomauthorization'} ],
    'fieldsList': {
      'equipmentkind_ID':{
        'canGetDefinitionList': 1
      },
      'equipmenttype_ID':{
        'canGetDefinitionList': 1
      }
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Script de règles : FINAL_WebhookRules_symptom

Par contre le script des règles métiers n’existe pas en standard. Il suffit donc de le créer en spécifique.

Bloc de code
// FINAL_WebhookRules_symptom

code      = TRANSLATE( "<varscript>arg1</varscript>" )
verb      = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput = TRANSLATE( "<varscript>arg3</varscript>" )

tableName               = "symptom"
entity                  = "symptom"
internalcode            = ""
codeTableName           = TRANSLATE( "code<varscript>tableName</varscript>" )
codeEntityName          = TRANSLATE( "code<varscript>entity</varscript>" )
internalcodeEntityName  = TRANSLATE( "internalcode<varscript>entity</varscript>" )
scriptOverload          = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" )

jsonResponse                        = DOCUMENT_CREATE_DOCUMENT()
ruleFields                          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" )
ruleOverloadFields                  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" )
ruleFieldsAdditionalTables          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" )
ruleOverloadFieldsAdditionalTables  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" )

// STANDARD RULES

IF( EQUALS( verb, "PUT" ) )THEN
  
  IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "0" )
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" )
    
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
    
  ENDIF
    
  jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity )
  VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput )
  
  
  IF ((LEN( code ) == 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THEN
    
    code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" )
    
  ENDIF
  
  IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" ) ) THEN
    
    internalcode = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" )
    
  ENDIF
  
  row_ID  = CALL_SCRIPT( "Func_GetIDFromCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>" )
  
ENDIF

// Rule overload
ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields )

IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
  
  response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" )
      
  IF( EQUALS( response, "0" ) )THEN
    
    IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
      
      errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage )

    ELSE
      
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" )
      
    ENDIF
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", response )
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
  
  ENDIF

ENDIF

DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "1" )
response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Script de surcharge de règles : FINAL_WebhookRulesOverload_symptom

Evidemment ce script n’existait pas en standard. Il suffit donc de le créer en spécifique.

Bloc de code
languagenone
// FINAL_WebhookRulesOverload_symptom

code          = TRANSLATE( "<varscript>arg1</varscript>" )
verb          = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput     = TRANSLATE( "<varscript>arg3</varscript>" )
ruleFields    = TRANSLATE( "<varscript>arg4</varscript>" )

jsonResponse = DOCUMENT_CREATE_DOCUMENT()

response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Ancre
Créer-webhook-sur-table-spécifique
Créer-webhook-sur-table-spécifique
Créer webhook sur une table spécifique

Création d’un nouveau webhook sur la table spécifique “sw_data_final_supplieraddress”.

Dictionnaire :

...

Script d’entrée : FINAL_WebhookSupplierAddress

Bloc de code
languagenone
tableName   = "final_supplieraddress"
entityName  = "final_supplieraddress"

INCLUDE( "FuncWebhook_BuildEndpoint" )

Script de définition : FINAL_WebhookDefinition_final_supplieraddress

Info

Bien noter la subtilité sur le nom de l’entité dans le code du script : final_supplieraddress

Bloc de code
languagenone
// FINAL_WebhookDefinition_final_supplieraddress

JSONFieldsDefinition = TRANSLATE( "
  { 
    'languageCode': '<varscript>languageCode</varscript>',
    'strictFilterMode': 1,
    'relatedTablesCount': 1,
    'relatedTables': [ 'final_supplier_ID' ],
    'authorizedTables': <varscript>authorizedTables</varscript>,
    'simpleFieldsList': 'codefinal_supplieraddress,final_name',
    'extendedFieldsListToExclude': '',
    'defaultFilters': [
     
    ],
    'strictFilters': [
      
    ],
    'strictOrderBy': [
    
    ],
    'outOfMainTableFields': [
      
    ],
    'standardOverload': {
      
    },
    'specificOverload':
    <varscript>specificOverload</varscript>,
    'simpleFields': [],
    'extendedFields': [],
    'strictFilterFields': [],
    'defaultFilterFields': [],
    'strictOrderByFields': []
  }
" )

INCLUDE( "FuncWebhook_BuildDefinition" )

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_final_supplieraddress

Info

Bien noter la subtilité sur le nom de l’entité dans le code du script : final_supplieraddress

Bloc de code
languagenone
// FINAL_WebhookRulesOverload_final_supplieraddress

code          = TRANSLATE( "<varscript>arg1</varscript>" )
verb          = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput     = TRANSLATE( "<varscript>arg3</varscript>" )
ruleFields    = TRANSLATE( "<varscript>arg4</varscript>" )

jsonResponse = DOCUMENT_CREATE_DOCUMENT()

response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Script de règles : FINAL_WebhookRules_final_supplieraddress

Info

Bien noter la subtilité sur le nom de l’entité dans le code du script : final_supplieraddress

Bloc de code
languagenone
// FINAL_WebhookRules_final_supplieraddress

code      = TRANSLATE( "<varscript>arg1</varscript>" )
verb      = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput = TRANSLATE( "<varscript>arg3</varscript>" )

tableName               = "final_supplieraddress"
entity                  = "final_supplieraddress"

internalcode            = ""
codeTableName           = TRANSLATE( "code<varscript>tableName</varscript>" )
codeEntityName          = TRANSLATE( "code<varscript>entity</varscript>" )
internalcodeEntityName  = TRANSLATE( "internalcode<varscript>entity</varscript>" )
scriptOverload          = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" )


jsonResponse                        = DOCUMENT_CREATE_DOCUMENT()
ruleFields                          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" )
ruleOverloadFields                  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" )
ruleFieldsAdditionalTables          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" )
ruleOverloadFieldsAdditionalTables  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" )

// STANDARD RULES

IF( EQUALS( verb, "PUT" ) )THEN
  
  IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "0" )
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" )
    
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
    
  ENDIF
    
  jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity )
  VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput )
  
  
  IF ((LEN( code ) == 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THEN
    
    code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" )
    
  ENDIF
  
  IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" ) ) THEN
    
    internalcode = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" )
    
  ENDIF
  
  row_ID  = CALL_SCRIPT( "Func_GetIDFromCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>" )
  
ENDIF

// Rule overload
ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields )

IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
  
  response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" )
      
  IF( EQUALS( response, "0" ) )THEN
    
    IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
      
      errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage )

    ELSE
      
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" )
      
    ENDIF
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", response )
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
  
  ENDIF

ENDIF

DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "1" )
response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Script de surcharge de règles : FINAL_WebhookRulesOverload_final_supplieraddress

Info

Bien noter la subtilité sur le nom de l’entité dans le code du script : final_supplieraddress

Bloc de code
languagenone
// FINAL_WebhookRulesOverload_final_supplieraddress

code          = TRANSLATE( "<varscript>arg1</varscript>" )
verb          = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput     = TRANSLATE( "<varscript>arg3</varscript>" )
ruleFields    = TRANSLATE( "<varscript>arg4</varscript>" )

jsonResponse = DOCUMENT_CREATE_DOCUMENT()

response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Compléter webhook existant pour mise à jour

Sur le webhook “Intervention” pour la méthode PUT, je veux également mettre à jour des données concernant les opérations.

Ceci va concerner les tables “sw_data_interventionoperationrange“ et “sw_data_interventionoperationtype“.

Script de définition : WebhookDefinition_intervention

Le script de définition “WebhookDefinition_intervention“ existe déjà en standard. Donc on y touche pas.

Script de surcharge de définition : WebhookDefinitionOverload_intervention

Le script de surcharge de définition “WebhookDefinitionOverload_intervention“ est déjà prévu en standard. Il suffit donc de surcharger ce script.

On reprend la propriété “authorizedTables“ du standard, complétée avec les 2 nouvelles tables.

Bloc de code
languagenone
// WebhookDefinitionOverload_intervention

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'authorizedTables': [{'tableName':'intervention'}, {'tableName':'interventionequipment'}, {'tableName':'interventionpart'}, {'tableName':'interventionoperationrange'}, {'tableName':'interventionoperationtype'}],
    'fieldsList': {
      
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Complément :

Il faut au minimum créer les scripts de définition pour “interventionoperationrange“ et “interventionoperationtype“ vu qu’ils n’existent pas en standard.

Script de définition : FINAL_WebhookDefinition_interventionoperationrange

Bloc de code
languagenone
// FINAL_WebhookDefinition_interventionoperationrange
tableName             = "interventionoperationrange"
specificOverload      = CALL_SCRIPT( "FINAL_WebhookDefinitionOverload_<varscript>tableName</varscript>" )
tableSchema           = DB_GET_TABLEINFO( "sw_data_<varscript>tableName</varscript>" )
tableSchemaDocument   = DOCUMENT_CREATE_FROM_JSON( tableSchema )
languageCode          = VARGET_SHELL( "languageCode", "WebhookDefinition" )
authorizedTables      = TRANSLATE( "[{'tableName':'<varscript>tableName</varscript>'}]" )

JSONFieldsDefinition = TRANSLATE( "
  { 
    'languageCode': '<varscript>languageCode</varscript>',
    'strictFilterMode': 1,
    'relatedTablesCount': 0,
    'relatedTables': [ ],
    'authorizedTables': <varscript>authorizedTables</varscript>,
    'simpleFieldsList': '',
    'extendedFieldsListToExclude': '',
    'defaultFilters': [
     
    ],
    'strictFilters': [
      
    ],
    'strictOrderBy': [
    
    ],
    'outOfMainTableFields': [
      
    ],
    'standardOverload': {
    
    },
    'specificOverload':
    <varscript>specificOverload</varscript>,
    'simpleFields': [],
    'extendedFields': [],
    'strictFilterFields': [],
    'defaultFilterFields': [],
    'strictOrderByFields': []
  }
" )

INCLUDE( "FuncWebhook_BuildDefinition" )

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_interventionoperationrange

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_interventionoperationrange

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'fieldsList': {
    
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Script de définition : FINAL_WebhookDefinition_interventionoperationtype

Bloc de code
languagenone
// FINAL_WebhookDefinition_interventionoperationtype
tableName             = "interventionoperationtype"
specificOverload      = CALL_SCRIPT( "FINAL_WebhookDefinitionOverload_<varscript>tableName</varscript>" )
tableSchema           = DB_GET_TABLEINFO( "sw_data_<varscript>tableName</varscript>" )
tableSchemaDocument   = DOCUMENT_CREATE_FROM_JSON( tableSchema )
languageCode          = VARGET_SHELL( "languageCode", "WebhookDefinition" )
authorizedTables      = TRANSLATE( "[{'tableName':'<varscript>tableName</varscript>'}]" )

JSONFieldsDefinition = TRANSLATE( "
  { 
    'languageCode': '<varscript>languageCode</varscript>',
    'strictFilterMode': 1,
    'relatedTablesCount': 0,
    'relatedTables': [ ],
    'authorizedTables': <varscript>authorizedTables</varscript>,
    'simpleFieldsList': '',
    'extendedFieldsListToExclude': '',
    'defaultFilters': [
     
    ],
    'strictFilters': [
      
    ],
    'strictOrderBy': [
    
    ],
    'outOfMainTableFields': [
      
    ],
    'standardOverload': {
    
    },
    'specificOverload':
    <varscript>specificOverload</varscript>,
    'simpleFields': [],
    'extendedFields': [],
    'strictFilterFields': [],
    'defaultFilterFields': [],
    'strictOrderByFields': []
  }
" )

INCLUDE( "FuncWebhook_BuildDefinition" )

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_interventionoperationtype

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_interventionoperationtype

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'fieldsList': {
    
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )