...
Lors de la création d’un nouveau webhookswebhook, cinq scripts sont obligatoires.
Pour le détail des scripts, vous pourrez vous appuyer sur ce qui a été effectué dans les scripts des webhooks standards.
Des exemple précis mais non exhaustifs seront données dans la suite de ce document.
...
Le code du script devra être de la forme : {Prefix}_WebhookDefinitionOverload_{entityname}.
Vous pouvez vous contenter de la trame de base, vu que votre définition sera déjà dans le script de définition.
Script de règles : C’est dans ce script que l’on applique les règles métiers. Ces règles s’appliqueront lors de la méthode PUT (ajout/mise à jour).
...
Le code du script devra être de la forme : {Prefix}_WebhookRulesOverload_{entityname}.
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 table standard
Création d’un nouveau webhook sur la table standard “sw_data_supplier” qui contient des champs spécifiques en surcharge FINAL.
Dictionnaire :
...
Script d’entrée : FINAL_WebhookSupplier
Bloc de code | ||
---|---|---|
| ||
tableName = "supplier"
entityName = "supplier"
INCLUDE( "FuncWebhook_BuildEndpoint" ) |
Script de définition : FINAL_WebhookDefinition_supplier
Bloc de code | ||
---|---|---|
| ||
// FINAL_WebhookDefinition_supplier // Webhook definition tableName = "supplier" 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_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
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 ) |
Script de surcharge de règles : FINAL_WebhookRulesOverload_supplier
Bloc de code | ||
---|---|---|
| ||
// FINAL_WebhookRulesOverload_supplier 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 ) |
Créer webhook sur table spécifique
...