The routines are executed through Web Services, therefore these executions must be connected and configured in the TOTVS Tec server.
Objective
The routines can be executed in Logix from workflow events of Fluig, allowing parameters to be sent and business rules for the process to be returned.
To perform the execution of a Logix routine from an event, you must follow the steps below:
- Use the customized Dataset LogixExecServiceDS.
- Send the parameters below as constraints to Dataset:
- Code of the company that will be used in the business rule;
- Routine of workflow that will be executed; and
- Values that will be used in the execution of the routine*.
- Retrieve the result in the execution of the routine through the default getValue function of the Dataset object*.
* The values that must be sent and the results of the routine follow the JSON string format.
Exemplo
function afterProcessFinish(processId) { var values, company, c1, c2, c3, dataset, result; //Retrieves the values of the process. values = { "componente": { "cod_empresa": new String(hAPI.getCardValue("cod_empresa")), "cod_item_compon": new String(hAPI.getCardValue("cod_item_compon")), "cod_grade_compon_1_orig": new String(hAPI.getCardValue("cod_grade_compon_1_orig")), "cod_grade_compon_2_orig": new String(hAPI.getCardValue("cod_grade_compon_2_orig")), "cod_grade_compon_3_orig": new String(hAPI.getCardValue("cod_grade_compon_3_orig")), "cod_grade_compon_4_orig": new String(hAPI.getCardValue("cod_grade_compon_4_orig")), "cod_grade_compon_5_orig": new String(hAPI.getCardValue("cod_grade_compon_5_orig")), "acao": new String(hAPI.getCardValue("acao")), "cod_item_compon_dest": new String(hAPI.getCardValue("cod_item_compon_dest")), "cod_grade_compon_1_dest": new String(hAPI.getCardValue("cod_grade_compon_1_dest")), "cod_grade_compon_2_dest": new String(hAPI.getCardValue("cod_grade_compon_2_dest")), "cod_grade_compon_3_dest": new String(hAPI.getCardValue("cod_grade_compon_3_dest")), "cod_grade_compon_4_dest": new String(hAPI.getCardValue("cod_grade_compon_4_dest")), "cod_grade_compon_5_dest": new String(hAPI.getCardValue("cod_grade_compon_5_dest")), "justificativa": new String(hAPI.getCardValue("justificativa")) } }; //Retrieves the value defined for the company code. company = values.componente.cod_empresa; //Converts the JSON object to JSON string. values = JSON.stringify(values); log.info("[LOGIX][WFMAN002] Values of the form recovered: " + values + "."); log.info("[LOGIX][WFMAN002] Starting execution of the routine WFMAN002."); c1 = DatasetFactory.createConstraint("company", company, null, ConstraintType.MUST); c2 = DatasetFactory.createConstraint("fn", "wfman002_process_finish", null, ConstraintType.MUST); c3 = DatasetFactory.createConstraint("values", values, null, ConstraintType.MUST); dataset = DatasetFactory.getDataset("LogixExecServiceDS", null, [c1, c2, c3], null); result = service.getValue(0, "result"); log.info("[LOGIX][WFMAN002] WFMAN002 routine executed, result sent: " + result + "."); //Converts the JSON string to JSON object. result = JSON.parse(result); if (result) { if (result.status) { log.info("[LOGIX][WFMAN002] " + result.msg); } else { log.error("[LOGIX][WFMAN002] Unable to complete the process: " + result.msg + "."); } } }
JSON String sending standards
//For master registers (object). { "componente": { "cod_empresa": "24", "cod_item_compon": "ITEM-TESTE", "cod_grade_compon_1_orig": "BRANCO", "cod_grade_compon_2_orig": "", "cod_grade_compon_3_orig": "", "cod_grade_compon_4_orig": "", "cod_grade_compon_5_orig": "", "acao": "1", "cod_item_compon_dest": "ITEM-TESTE-NOVO", "cod_grade_compon_1_dest": "PRETO", "cod_grade_compon_2_dest": "", "cod_grade_compon_3_dest": "", "cod_grade_compon_4_dest": "", "cod_grade_compon_5_dest": "", "justificativa": "ALTERACAO DO COMPONENTE ITEM-TESTE BRANCO PARA ITEM-TESTE-NOVO PRETO." } } //For detail registers (lists). { "componentes": [ { "cod_empresa": "24", "cod_item_compon": "ITEM-TESTE", "cod_grade_compon_1_orig": "BRANCO", "cod_grade_compon_2_orig": "", "cod_grade_compon_3_orig": "", "cod_grade_compon_4_orig": "", "cod_grade_compon_5_orig": "", "acao": "1", "cod_item_compon_dest": "ITEM-TESTE-NOVO", "cod_grade_compon_1_dest": "PRETO", "cod_grade_compon_2_dest": "", "cod_grade_compon_3_dest": "", "cod_grade_compon_4_dest": "", "cod_grade_compon_5_dest": "", "justificativa": "ALTERACAO DO COMPONENTE ITEM-TESTE BRANCO PARA ITEM-TESTE-NOVO PRETO." }, { "cod_empresa": "24", "cod_item_compon": "ITEM-TESTE-NOVO", "cod_grade_compon_1_orig": "PRETO", "cod_grade_compon_2_orig": "", "cod_grade_compon_3_orig": "", "cod_grade_compon_4_orig": "", "cod_grade_compon_5_orig": "", "acao": "1", "cod_item_compon_dest": "ITEM-TESTE", "cod_grade_compon_1_dest": "BRANCO", "cod_grade_compon_2_dest": "", "cod_grade_compon_3_dest": "", "cod_grade_compon_4_dest": "", "cod_grade_compon_5_dest": "", "justificativa": "ALTERACAO DO COMPONENTE ITEM-TESTE-NOVO PRETO PARA ITEM-TESTE BRANCO." } ] }
In order for the execution of the routine in Logix to occur, follow the steps below:
- Create the 4GL routine without parameters.
- The values sent must be recovered through the function _ADVPL_WfGetParameterValue.
- To retrieve the number of child fields in the values sent, use the function _ADVPL_WfGetParameterLength.
- The function must return a RECORD variable with at least two attributes*:
- status: SMALLINT type, must have a TRUE or FALSE value to indicate if routine was executed successfully; and
- msg: CHAR type, must have a short message in order for it to be displayed for the viewer in the Fluig LOG file or on the screen.
* The RECORD return variable may have other attributes according to the needs of the process.
Exemplo
#-------------------------------------# FUNCTION wfman002_alterar_componentes() #-------------------------------------# DEFINE lr_return RECORD status SMALLINT, msg CHAR(300) END RECORD DEFINE lr_comp_orig, lr_comp_dest RECORD cod_item_compon LIKE estrut_grade.cod_item_compon, cod_grade_comp_1 LIKE estrut_grade.cod_grade_comp_1, cod_grade_comp_2 LIKE estrut_grade.cod_grade_comp_2, cod_grade_comp_3 LIKE estrut_grade.cod_grade_comp_3, cod_grade_comp_4 LIKE estrut_grade.cod_grade_comp_4, cod_grade_comp_5 LIKE estrut_grade.cod_grade_comp_5 END RECORD DEFINE la_item_pai ARRAY[100] OF RECORD cod_item_pai LIKE estrut_grade.cod_item_pai, cod_grade_1 LIKE estrut_grade.cod_grade_1, cod_grade_2 LIKE estrut_grade.cod_grade_2, cod_grade_3 LIKE estrut_grade.cod_grade_3, cod_grade_4 LIKE estrut_grade.cod_grade_4, cod_grade_5 LIKE estrut_grade.cod_grade_5, qtd_necessaria LIKE estrut_grade.qtd_necessaria, dat_validade_ini LIKE estrut_grade.dat_validade_ini, dat_validade_fim LIKE estrut_grade.dat_validade_fim, num_sequencia LIKE estrut_grade.num_sequencia END RECORD DEFINE l_justificativa CHAR(300), l_acao CHAR(001), l_altera_item CHAR(001) DEFINE l_ind, l_item_ind, l_item_count SMALLINT IF LOG_initApp("MANENG") > 0 THEN LET lr_return.status = FALSE LET lr_return.msg = "Usuário ",p_user CLIPPED," sem permissão para acessar a rotina." RETURN lr_return END IF LET lr_comp_orig.cod_item_compon = _ADVPL_WfGetParameterValue("componentes","cod_item_compon_orig") LET lr_comp_orig.cod_grade_comp_1 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_1_orig") LET lr_comp_orig.cod_grade_comp_2 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_2_orig") LET lr_comp_orig.cod_grade_comp_3 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_3_orig") LET lr_comp_orig.cod_grade_comp_4 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_4_orig") LET lr_comp_orig.cod_grade_comp_5 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_5_orig") LET lr_comp_dest.cod_item_compon = _ADVPL_WfGetParameterValue("componentes","cod_item_compon_dest") LET lr_comp_dest.cod_grade_comp_1 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_1_dest") LET lr_comp_dest.cod_grade_comp_2 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_2_dest") LET lr_comp_dest.cod_grade_comp_3 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_3_dest") LET lr_comp_dest.cod_grade_comp_4 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_4_dest") LET lr_comp_dest.cod_grade_comp_5 = _ADVPL_WfGetParameterValue("componentes","cod_grade_comp_5_dest") LET l_justificativa = _ADVPL_WfGetParameterValue("componentes","justificativa") LET l_acao = _ADVPL_WfGetParameterValue("componentes","slct_acao") #Checks the codes of the source grid. IF lr_comp_orig.cod_grade_comp_1 IS NULL THEN LET lr_comp_orig.cod_grade_comp_1 = " " END IF IF lr_comp_orig.cod_grade_comp_2 IS NULL THEN LET lr_comp_orig.cod_grade_comp_2 = " " END IF IF lr_comp_orig.cod_grade_comp_3 IS NULL THEN LET lr_comp_orig.cod_grade_comp_3 = " " END IF IF lr_comp_orig.cod_grade_comp_4 IS NULL THEN LET lr_comp_orig.cod_grade_comp_4 = " " END IF IF lr_comp_orig.cod_grade_comp_5 IS NULL THEN LET lr_comp_orig.cod_grade_comp_5 = " " END IF #Checks the codes of the target grid. IF lr_comp_dest.cod_grade_comp_1 IS NULL THEN LET lr_comp_dest.cod_grade_comp_1 = " " END IF IF lr_comp_dest.cod_grade_comp_2 IS NULL THEN LET lr_comp_dest.cod_grade_comp_2 = " " END IF IF lr_comp_dest.cod_grade_comp_3 IS NULL THEN LET lr_comp_dest.cod_grade_comp_3 = " " END IF IF lr_comp_dest.cod_grade_comp_4 IS NULL THEN LET lr_comp_dest.cod_grade_comp_4 = " " END IF IF lr_comp_dest.cod_grade_comp_5 IS NULL THEN LET lr_comp_dest.cod_grade_comp_5 = " " END IF LET l_item_ind = 0 LET l_item_count = _ADVPL_WfGetParameterLength("item_pai") FOR l_ind = 1 TO l_item_count LET l_altera_item = _ADVPL_WfGetParameterValue("item_pai","altera_item",l_ind) IF l_altera_item = "S" THEN LET l_item_ind = l_item_ind + 1 LET la_item_pai[l_item_ind].cod_item_pai = _ADVPL_WfGetParameterValue("item_pai","cod_item_pai",l_ind) LET la_item_pai[l_item_ind].cod_grade_1 = _ADVPL_WfGetParameterValue("item_pai","cod_grade_1",l_ind) LET la_item_pai[l_item_ind].cod_grade_2 = _ADVPL_WfGetParameterValue("item_pai","cod_grade_2",l_ind) LET la_item_pai[l_item_ind].cod_grade_3 = _ADVPL_WfGetParameterValue("item_pai","cod_grade_3",l_ind) LET la_item_pai[l_item_ind].cod_grade_4 = _ADVPL_WfGetParameterValue("item_pai","cod_grade_4",l_ind) LET la_item_pai[l_item_ind].cod_grade_5 = _ADVPL_WfGetParameterValue("item_pai","cod_grade_5",l_ind) LET la_item_pai[l_item_ind].qtd_necessaria = _ADVPL_WfGetParameterValue("item_pai","qtd_necessaria",l_ind) LET la_item_pai[l_item_ind].dat_validade_ini = _ADVPL_WfGetParameterValue("item_pai","dat_validade_ini",l_ind) LET la_item_pai[l_item_ind].dat_validade_fim = _ADVPL_WfGetParameterValue("item_pai","dat_validade_fim",l_ind) LET la_item_pai[l_item_ind].num_sequencia = _ADVPL_WfGetParameterValue("item_pai","num_sequencia",l_ind) #Checks the codes of the grid of the parent item. IF la_item_pai[l_item_ind].cod_grade_1 IS NULL THEN LET la_item_pai[l_item_ind].cod_grade_1 = " " END IF IF la_item_pai[l_item_ind].cod_grade_2 IS NULL THEN LET la_item_pai[l_item_ind].cod_grade_2 = " " END IF IF la_item_pai[l_item_ind].cod_grade_3 IS NULL THEN LET la_item_pai[l_item_ind].cod_grade_3 = " " END IF IF la_item_pai[l_item_ind].cod_grade_4 IS NULL THEN LET la_item_pai[l_item_ind].cod_grade_4 = " " END IF IF la_item_pai[l_item_ind].cod_grade_5 IS NULL THEN LET la_item_pai[l_item_ind].cod_grade_5 = " " END IF END IF END FOR { Business rule 4GL. } LET lr_return.status = TRUE LET lr_return.msg = "Item componente alterado com sucesso." RETURN lr_return END FUNCTION
Default return JSON String
{ "success": true|false, "msg": "Mensagem retornada pela rotina." }
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas