...
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
...
language | none |
---|
...
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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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”.
Dictionnaire :
...
symptom”.
Script d’entrée : FINAL_WebhookSupplierAddressWebhookSymptom
Bloc de code | ||
---|---|---|
| ||
tableName = "final_supplieraddresssymptom" entityName = "final_supplieraddresssymptom" INCLUDE( "FuncWebhook_BuildEndpoint" ) |
Script de définition : FINAL_ WebhookDefinition_final_supplieraddress
...
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 | ||
---|---|---|
| ||
// FINAL_WebhookDefinition_final_supplieraddressWebhookDefinitionOverload_symptom JSONFieldsDefinition =languageCode TRANSLATE( " { = VARGET_SHELL( "languageCode", "WebhookDefinition" ) specificOverload = 'languageCode': '<varscript>languageCode</varscript>',TRANSLATE( " { 'strictFilterModeextendedFieldsListToExclude': 1'', 'relatedTablesCount': 13, 'relatedTables': [ 'equipmenttype_ID', 'final_supplierequipmentkind_ID', 'symptom_ID_parent' ], 'authorizedTables': <varscript>authorizedTables</varscript>, 'simpleFieldsList': 'codefinal_supplieraddress,final_name'[{'tableName':'symptom'}, {'tableName':'symptomauthorization'}], 'extendedFieldsListToExcludecascadeDeleteTables': [ {'tableName':'symptomauthorization'} ], 'defaultFiltersfieldsList': [{ 'equipmentkind_ID':{ ], 'strictFilterscanGetDefinitionList': 1 [ }, 'equipmenttype_ID':{ ], 'strictOrderBycanGetDefinitionList': 1 [ } ]}, 'outOfMainTableFields'strictFilters: [ ], 'standardOverloadstrictOrderBy': {[ }], 'specificOverloadoutOfMainTableFields': [ <varscript>specificOverload</varscript>, 'simpleFields': [], } " ) 'extendedFields': [], 'strictFilterFields': [] 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 | ||
---|---|---|
| ||
// 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éation d’un nouveau webhook sur la table spécifique “sw_data_final_supplieraddress”.
Dictionnaire :
...
Script d’entrée : FINAL_WebhookSupplierAddress
Bloc de code | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// 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 | ||
---|---|---|
| ||
// WebhookDefinitionOverload_intervention languageCode = VARGET_SHELL( "languageCode", "WebhookDefinition" ) specificOverload = TRANSLATE( " { 'extendedFieldsListToExclude': '', 'defaultFilterFieldsauthorizedTables': [{'tableName':'intervention'}, {'tableName':'interventionequipment'}, {'tableName':'interventionpart'}, {'tableName':'interventionoperationrange'}, {'tableName':'interventionoperationtype'}], 'strictOrderByFieldsfieldsList': [] { } " ) 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 | ||
---|---|---|
| ||
// FINAL_WebhookRulesOverload_final_supplieraddress code }, strictFilters: [ = TRANSLATE( "<varscript>arg1</varscript>" ) verb], 'strictOrderBy': [ = TRANSLATE( "<varscript>arg2</varscript>" ) dataInput ], = TRANSLATE( "<varscript>arg3</varscript>" ) ruleFields'outOfMainTableFields': [ = TRANSLATE( "<varscript>arg4</varscript>" ) jsonResponse = DOCUMENT_CREATE_DOCUMENT() response] = DOCUMENT_SERIALIZE( jsonResponse, "json } " ) RETURN( response"<varscript>specificOverload</varscript>" ) |
Script de règles : FINAL_WebhookRules_final_supplieraddress
...
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 | ||
---|---|---|
| ||
// FINAL_WebhookRulesWebhookDefinition_final_supplieraddressinterventionoperationrange tableName code = TRANSLATE( "<varscript>arg1</varscript>" ) verb = "interventionoperationrange" specificOverload = TRANSLATE( "<varscript>arg2</varscript>" ) dataInput = TRANSLATECALL_SCRIPT( "<varscript>arg3<FINAL_WebhookDefinitionOverload_<varscript>tableName</varscript>" ) tableSchema tableName = = "final_supplieraddress" entity DB_GET_TABLEINFO( "sw_data_<varscript>tableName</varscript>" ) tableSchemaDocument = DOCUMENT_CREATE_FROM_JSON( tableSchema ) languageCode = =VARGET_SHELL( "languageCode", "final_supplieraddressWebhookDefinition" ) internalcodeauthorizedTables = TRANSLATE( "[{'tableName':'<varscript>tableName</varscript>'}]" ) JSONFieldsDefinition = TRANSLATE( "" codeTableName{ 'languageCode': '<varscript>languageCode</varscript>', = TRANSLATE( "code<varscript>tableName</varscript>" ) codeEntityName 'strictFilterMode': 1, 'relatedTablesCount': 0, 'relatedTables': =[ TRANSLATE( "code<varscript>entity</varscript>" ) internalcodeEntityName = TRANSLATE( "internalcode<varscript>entity</varscript>" ) scriptOverload ], 'authorizedTables': <varscript>authorizedTables</varscript>, 'simpleFieldsList': '', 'extendedFieldsListToExclude': '', = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" ) jsonResponse 'defaultFilters': [ ], 'strictFilters': [ = DOCUMENT_CREATE_DOCUMENT() ruleFields ], 'strictOrderBy': [ ], 'outOfMainTableFields': [ = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" ) ruleOverloadFields ], 'standardOverload': { = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" ) ruleFieldsAdditionalTables }, 'specificOverload': <varscript>specificOverload</varscript>, = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" ) ruleOverloadFieldsAdditionalTables = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" ) // STANDARD RULES IF( EQUALS( verb, "PUT" ) )THEN 'simpleFields': [], 'extendedFields': [], 'strictFilterFields': [], 'defaultFilterFields': [], IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN 'strictOrderByFields': [] } " ) INCLUDE( "FuncWebhook_BuildDefinition" ) |
Script de surcharge de définition : FINAL_WebhookDefinitionOverload_interventionoperationrange
Bloc de code | ||
---|---|---|
| ||
// FINAL_WebhookDefinitionOverload_interventionoperationrange languageCode = DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "responseVARGET_SHELL( "languageCode", "0WebhookDefinition" ) specificOverload = DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" ) TRANSLATE( " { 'extendedFieldsListToExclude': '', 'fieldsList': { }, strictFilters: response[ = DOCUMENT_SERIALIZE( jsonResponse, "json" ) RETURN( response ) ], 'strictOrderBy': [ ENDIF jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity ) VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput ) ], 'outOfMainTableFields': [ IF] ((LEN( code )} ==" 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THENRETURN( "<varscript>specificOverload</varscript>" ) |
Script de définition : FINAL_WebhookDefinition_interventionoperationtype
Bloc de code | ||
---|---|---|
| ||
// FINAL_WebhookDefinition_interventionoperationtype tableName code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ) = "interventionoperationtype" specificOverload ENDIF IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName<= CALL_SCRIPT( "FINAL_WebhookDefinitionOverload_<varscript>tableName</varscript>" ) )tableSchema THEN internalcode = JSONDB_GET_FROM_PATH( jsonDataInput,TABLEINFO( "<varscript>internalcodeEntityName<sw_data_<varscript>tableName</varscript>" ) tableSchemaDocument = DOCUMENT_CREATE_FROM_JSON( tableSchema ) languageCode ENDIF row_ID = CALLVARGET_SCRIPTSHELL( "Func_GetIDFromCodelanguageCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>WebhookDefinition" ) authorizedTables = TRANSLATE( "[{'tableName':'<varscript>tableName</varscript>'}]" ) JSONFieldsDefinition = ENDIFTRANSLATE( " // Rule overload{ ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields ) IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN 'languageCode': '<varscript>languageCode</varscript>', 'strictFilterMode': 1, 'relatedTablesCount': 0, response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" ) 'relatedTables': [ ], 'authorizedTables': <varscript>authorizedTables</varscript>, IF( EQUALS( response, "0" ) )THEN 'simpleFieldsList': '', 'extendedFieldsListToExclude': '', IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN'defaultFilters': [ ], errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )'strictFilters': [ DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage ) ], 'strictOrderBy': [ ELSE ], 'outOfMainTableFields': DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" ) [ ], 'standardOverload': { ENDIF }, 'specificOverload': 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 <varscript>specificOverload</varscript>,
'simpleFields': [],
'extendedFields': [],
'strictFilterFields': [],
'defaultFilterFields': [],
'strictOrderByFields': []
}
" )
INCLUDE( "FuncWebhook_BuildDefinition" ) |
Script de surcharge de définition : FINAL_WebhookDefinitionOverload_interventionoperationtype
Bloc de code | ||
---|---|---|
| ||
// FINAL_WebhookRulesOverloadWebhookDefinitionOverload_final_supplieraddressinterventionoperationtype codelanguageCode = VARGET_SHELL( "languageCode", "WebhookDefinition" ) specificOverload = TRANSLATE( "<varscript>arg1</varscript>" ) verb { 'extendedFieldsListToExclude': '', 'fieldsList': { }, strictFilters: [ ], 'strictOrderBy': [ = TRANSLATE( "<varscript>arg2</varscript>" ) dataInput ], = TRANSLATE( "<varscript>arg3</varscript>" ) ruleFields'outOfMainTableFields': [ = TRANSLATE( "<varscript>arg4</varscript>" ) jsonResponse = DOCUMENT_CREATE_DOCUMENT() response] = DOCUMENT_SERIALIZE( jsonResponse, } "json" ) RETURN( response ) |
Compléter webhook existant
Script de définition : FINAL_WebhookDefinition_interventionoperationrange
...
"<varscript>specificOverload</varscript>" ) |