<list>
  <ProcessDefinition>
    <processDefinitionPK>
      <companyId>1</companyId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
    </processDefinitionPK>
    <processDescription>Lançamento de documento</processDescription>
    <instruction>Este Flow permite ao colaborador lançar dados referentes a um documento, seja uma nota, recibo, boleto ou outro que a empresa possua, com a obrigatoriedade de anexar o documento citado. Quando aprovada a etapa de Análise do documento, o mesmo será publicado no ECM e herdará as propriedades de validade e notificação.</instruction>
    <active>true</active>
    <publicProcess>true</publicProcess>
    <volumeId>Default</volumeId>
    <categoryId>Documentos</categoryId>
    <managerEngineAllocationId></managerEngineAllocationId>
    <snapshotFrequency>0</snapshotFrequency>
    <baseDay>0</baseDay>
    <baseMonth>0</baseMonth>
    <periodId>Default</periodId>
    <uniqueCardVersion>false</uniqueCardVersion>
    <keyWord></keyWord>
    <complementsLevel>1</complementsLevel>
    <notifyRequisitionerComplements>true</notifyRequisitionerComplements>
    <notifyManagerComplements>false</notifyManagerComplements>
    <deadlineTime>86400</deadlineTime>
    <warningDeadlineTime>43200</warningDeadlineTime>
    <notifyAuthorityComplements>true</notifyAuthorityComplements>
  </ProcessDefinition>
  <ProcessDefinitionVersion>
    <processDefinitionVersionPK>
      <companyId>1</companyId>
      <processId>Lançamento de documento</processId>
      <version>13</version>
    </processDefinitionVersionPK>
    <versionDescription></versionDescription>
    <formId>41254</formId>
    <editionMode>true</editionMode>
    <updateAttachmentsVersion>false</updateAttachmentsVersion>
    <controlsAttachmentsSecurity>false</controlsAttachmentsSecurity>
    <active>true</active>
    <blockedVersion>false</blockedVersion>
    <counterSign>false</counterSign>
    <openInstances>0</openInstances>
    <bpmnVersion>2</bpmnVersion>
    <processStates/>
    <favorito>false</favorito>
    <inheritFormSecurity>false</inheritFormSecurity>
    <mobileReady>false</mobileReady>
  </ProcessDefinitionVersion>
  <list>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>4</sequence>
      </processStatePK>
      <stateName>Lançar documento</stateName>
      <stateDescription>Lançar documento</stateDescription>
      <instruction></instruction>
      <deadlineTime>0</deadlineTime>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId></engineAllocationId>
      <engineAllocationConfiguration></engineAllocationConfiguration>
      <selectColleague>1</selectColleague>
      <initialState>true</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>3600</allowanceAuthorityTime>
      <frequenceAuthorityTime>3600</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>true</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>true</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>120</positionX>
      <positionY>100</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>0</stateType>
      <bpmnType>10</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <noticeExpirationAuthorityTime>0</noticeExpirationAuthorityTime>
      <noticeExpirationRequisitionerTime>0</noticeExpirationRequisitionerTime>
      <noticeExpirationManagerTime>0</noticeExpirationManagerTime>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>5</sequence>
      </processStatePK>
      <stateName>Analisar documento</stateName>
      <stateDescription>Analisar documento</stateDescription>
      <instruction></instruction>
      <deadlineTime>86400</deadlineTime>
      <deadlineFieldName></deadlineFieldName>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId>Pool Grupo</engineAllocationId>
      <engineAllocationConfiguration>&lt;AssignmentController&gt;&lt;Group&gt;Fiscal&lt;/Group&gt;&lt;/AssignmentController&gt;</engineAllocationConfiguration>
      <selectColleague>1</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>3600</allowanceAuthorityTime>
      <frequenceAuthorityTime>3600</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>true</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>280</positionX>
      <positionY>241</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId>Default</periodId>
      <stateType>0</stateType>
      <bpmnType>80</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <noticeExpirationAuthorityTime>0</noticeExpirationAuthorityTime>
      <noticeExpirationRequisitionerTime>0</noticeExpirationRequisitionerTime>
      <noticeExpirationManagerTime>0</noticeExpirationManagerTime>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
      <executionType>0</executionType>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>15</sequence>
      </processStatePK>
      <stateName>Integração Contas a pagar</stateName>
      <stateDescription>Integração Contas a pagar</stateDescription>
      <instruction></instruction>
      <deadlineTime>0</deadlineTime>
      <deadlineFieldName></deadlineFieldName>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId></engineAllocationId>
      <selectColleague>1</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>false</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>0</allowanceAuthorityTime>
      <frequenceAuthorityTime>0</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>true</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>510</positionX>
      <positionY>475</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>0</stateType>
      <bpmnType>82</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <noticeExpirationAuthorityTime>0</noticeExpirationAuthorityTime>
      <noticeExpirationRequisitionerTime>0</noticeExpirationRequisitionerTime>
      <noticeExpirationManagerTime>0</noticeExpirationManagerTime>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
      <executionType>1</executionType>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>22</sequence>
      </processStatePK>
      <stateName>Revisar Integração</stateName>
      <stateDescription>Revisar Integração</stateDescription>
      <instruction></instruction>
      <deadlineTime>0</deadlineTime>
      <deadlineFieldName></deadlineFieldName>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <selectColleague>1</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>3600</allowanceAuthorityTime>
      <frequenceAuthorityTime>3600</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>true</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>510</positionX>
      <positionY>310</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>0</stateType>
      <bpmnType>80</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <noticeExpirationAuthorityTime>0</noticeExpirationAuthorityTime>
      <noticeExpirationRequisitionerTime>0</noticeExpirationRequisitionerTime>
      <noticeExpirationManagerTime>0</noticeExpirationManagerTime>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
      <executionType>0</executionType>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>24</sequence>
      </processStatePK>
      <stateName>Intermediário</stateName>
      <stateDescription>Intermediário</stateDescription>
      <instruction>Evento intermediário do processo</instruction>
      <deadlineTime>0</deadlineTime>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId></engineAllocationId>
      <engineAllocationConfiguration></engineAllocationConfiguration>
      <selectColleague>0</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>1</allowanceAuthorityTime>
      <frequenceAuthorityTime>1</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>true</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>570</positionX>
      <positionY>480</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>0</stateType>
      <bpmnType>43</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
      <parentSequence>15</parentSequence>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>14</sequence>
      </processStatePK>
      <stateName>Cancelar</stateName>
      <stateDescription>Cancelar</stateDescription>
      <instruction>Atividade final do processo</instruction>
      <deadlineTime>0</deadlineTime>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId></engineAllocationId>
      <engineAllocationConfiguration></engineAllocationConfiguration>
      <selectColleague>0</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>0</allowanceAuthorityTime>
      <frequenceAuthorityTime>1</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>false</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>550</positionX>
      <positionY>260</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>6</stateType>
      <bpmnType>65</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
    </ProcessState>
    <ProcessState>
      <processStatePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>17</sequence>
      </processStatePK>
      <stateName>Fim</stateName>
      <stateDescription>Fim</stateDescription>
      <instruction>Atividade final do processo</instruction>
      <deadlineTime>0</deadlineTime>
      <joint>false</joint>
      <agreementPercentage>0</agreementPercentage>
      <engineAllocationId></engineAllocationId>
      <engineAllocationConfiguration></engineAllocationConfiguration>
      <selectColleague>0</selectColleague>
      <initialState>false</initialState>
      <notifyAuthorityDelay>true</notifyAuthorityDelay>
      <notifyRequisitionerDelay>false</notifyRequisitionerDelay>
      <allowanceAuthorityTime>0</allowanceAuthorityTime>
      <frequenceAuthorityTime>1</frequenceAuthorityTime>
      <allowanceRequisitionerTime>0</allowanceRequisitionerTime>
      <frequenceRequisitionerTime>0</frequenceRequisitionerTime>
      <transferAttachments>false</transferAttachments>
      <subProcessId></subProcessId>
      <formFolder>0</formFolder>
      <notifyAuthorityFollowUp>false</notifyAuthorityFollowUp>
      <notifyRequisitionerFollowUp>false</notifyRequisitionerFollowUp>
      <automatic>false</automatic>
      <positionX>790</positionX>
      <positionY>503</positionY>
      <forecastedEffortType>0</forecastedEffortType>
      <forecastedEffort>0</forecastedEffort>
      <notifyManagerFollowUp>false</notifyManagerFollowUp>
      <notifyManagerDelay>false</notifyManagerDelay>
      <allowanceManagerTime>0</allowanceManagerTime>
      <frequenceManagerTime>0</frequenceManagerTime>
      <inhibitTransfer>false</inhibitTransfer>
      <periodId></periodId>
      <stateType>6</stateType>
      <bpmnType>60</bpmnType>
      <signalId>0</signalId>
      <counterSign>false</counterSign>
      <openInstances>0</openInstances>
      <destinationStates/>
      <digitalSignature>false</digitalSignature>
    </ProcessState>
  </list>
  <list/>
  <list>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>6</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>4</initialStateSequence>
      <finalStateSequence>5</finalStateSequence>
      <returnLabel></returnLabel>
      <name></name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
    </ProcessLink>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>13</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>5</initialStateSequence>
      <finalStateSequence>14</finalStateSequence>
      <returnLabel></returnLabel>
      <name>Cancelar</name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
      <movementTitle></movementTitle>
      <movementDescription></movementDescription>
      <movementAccessLinkDescription></movementAccessLinkDescription>
    </ProcessLink>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>16</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>5</initialStateSequence>
      <finalStateSequence>15</finalStateSequence>
      <returnLabel></returnLabel>
      <name></name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
    </ProcessLink>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>18</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>15</initialStateSequence>
      <finalStateSequence>17</finalStateSequence>
      <returnLabel></returnLabel>
      <name></name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
    </ProcessLink>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>25</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>24</initialStateSequence>
      <finalStateSequence>22</finalStateSequence>
      <returnLabel></returnLabel>
      <name></name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
    </ProcessLink>
    <ProcessLink>
      <processLinkPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <linkSequence>26</linkSequence>
      </processLinkPK>
      <actionLabel></actionLabel>
      <returnPermited>false</returnPermited>
      <initialStateSequence>22</initialStateSequence>
      <finalStateSequence>15</finalStateSequence>
      <returnLabel></returnLabel>
      <name></name>
      <automaticLink>false</automaticLink>
      <defaultLink>false</defaultLink>
      <type>0</type>
    </ProcessLink>
  </list>
  <list/>
  <list>
    <WorkflowProcessEvent>
      <workflowProcessEventPK>
        <companyId>1</companyId>
        <eventId>servicetask15</eventId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
      </workflowProcessEventPK>
      <eventDescription>function servicetask15(attempt, message) {
    var payload = buildSe2010Payload();
    appendDebugSe2010(&quot;servicetask15: payload=&quot; + safeStringify(payload));

    var response = invokeSe2010(payload);
    appendDebugSe2010(&quot;servicetask15: status=&quot; + response.httpStatus + &quot; body=&quot; + response.raw);

    if (!response.success) {
        throw &quot;Falha ao enviar dados para Protheus SE2010. Status HTTP: &quot; + response.httpStatus + &quot;.&quot;;
    }
}

function buildSe2010Payload() {
    var payload = {
        FILIAL: requiredCard(&quot;FILIAL&quot;),
        PREFIXO: requiredCard(&quot;PREFIXO&quot;),
        NUMERO: requiredCard(&quot;NUMERO&quot;),
        PARCELA: requiredCard(&quot;PARCELA&quot;),
        TIPO: requiredCard(&quot;TIPO&quot;),
        NATUREZA: requiredCard(&quot;NATUREZA&quot;),
        COD_FORN: requiredCard(&quot;COD_FORN&quot;),
        LOJA: requiredCard(&quot;LOJA&quot;),
        EMISSAO: normalizeDate(requiredCard(&quot;EMISSAO&quot;), &quot;EMISSAO&quot;),
        VENCIMENTO: normalizeDate(requiredCard(&quot;VENCIMENTO&quot;), &quot;VENCIMENTO&quot;),
        VENC_REAL: normalizeDate(requiredCard(&quot;VENC_REAL&quot;), &quot;VENC_REAL&quot;),
        VALOR: parseMoney(requiredCard(&quot;VALORtotal&quot;, &quot;VALOR&quot;)),
        HISTORICO: requiredCard(&quot;HISTORICO&quot;),
        CODIGO_BARRAS: card(&quot;CODIGO_BARRAS&quot;),
        CENTRO_CUSTO: requiredCard(&quot;CENTRO_CUSTO&quot;)
    };

    return payload;
}

function invokeSe2010(payload) {
    var serviceCode = card(&quot;service_code_se2010&quot;) || &quot;protheus_teste&quot;;
    var endpoint = card(&quot;endpoint_se2010&quot;) || &quot;https://comerciode186920.protheus.cloudtotvs.com.br:4050/rest/uf_se2010&quot;;

    var requestData = {
        companyId: getCompanyIdSafe(),
        serviceCode: serviceCode,
        endpoint: endpoint,
        method: &quot;post&quot;,
        timeoutService: &quot;120&quot;,
        headers: {
            &quot;Content-Type&quot;: &quot;application/json&quot;,
            &quot;Accept&quot;: &quot;application/json&quot;
        },
        options: {
            encoding: &quot;UTF-8&quot;,
            mediaType: &quot;application/json&quot;,
            useSSL: true
        },
        params: payload
    };

    var clientService = fluigAPI.getAuthorizeClientService();
    var vo = clientService.invoke(JSON.stringify(requestData));
    var raw = vo ? String(vo.getResult() || &quot;&quot;) : &quot;&quot;;

    if (!raw) {
        throw &quot;Resposta vazia da API SE2010.&quot;;
    }

    var httpStatus = getHttpStatus(vo);
    var parsed = parseJsonSafe(raw);
    var success = httpStatus &gt;= 200 &amp;&amp; httpStatus &lt; 300;

    if (parsed &amp;&amp; parsed.success === false) {
        success = false;
    }

    return {
        success: success,
        httpStatus: httpStatus,
        raw: raw,
        parsed: parsed
    };
}

function requiredCard() {
    var value = &quot;&quot;;

    for (var i = 0; i &lt; arguments.length; i++) {
        value = card(arguments[i]);
        if (value) {
            break;
        }
    }

    if (!value) {
        throw &quot;Campo obrigatorio nao informado para envio Protheus: &quot; + arguments[0];
    }

    return value;
}

function card(name) {
    return ((hAPI.getCardValue(name) || &quot;&quot;) + &quot;&quot;).replace(/^\s+|\s+$/g, &quot;&quot;);
}

function normalizeDate(value, fieldName) {
    var digits = (value || &quot;&quot;).replace(/\D/g, &quot;&quot;);
    if (digits.length !== 8) {
        throw &quot;Data invalida no campo &quot; + fieldName + &quot;. Informe no formato YYYYMMDD.&quot;;
    }
    return digits;
}

function parseMoney(value) {
    var raw = (value || &quot;&quot;).toString().replace(/\s/g, &quot;&quot;);
    if (!raw) {
        return 0;
    }

    if (raw.indexOf(&quot;,&quot;) &gt;= 0) {
        raw = raw.replace(/\./g, &quot;&quot;).replace(&quot;,&quot;, &quot;.&quot;);
    } else {
        var dotCount = (raw.match(/\./g) || []).length;
        if (dotCount &gt; 1) {
            raw = raw.replace(/\./g, &quot;&quot;);
        }
    }

    var parsed = parseFloat(raw);
    if (isNaN(parsed)) {
        throw &quot;Valor invalido para envio Protheus: &quot; + value;
    }

    return parseFloat(parsed.toFixed(2));
}

function getCompanyIdSafe() {
    try {
        if (typeof getValue === &quot;function&quot;) {
            return String(getValue(&quot;WKCompany&quot;) || &quot;1&quot;);
        }
    } catch (e) {
        // ignore
    }
    return &quot;1&quot;;
}

function getHttpStatus(vo) {
    try {
        var status = parseInt(String(vo.getHttpStatusResult() || &quot;0&quot;), 10);
        if (!isNaN(status) &amp;&amp; status &gt; 0) {
            return status;
        }
    } catch (e) {
        // ignore
    }

    return 200;
}

function parseJsonSafe(value) {
    try {
        return JSON.parse(value);
    } catch (e) {
        return null;
    }
}

function safeStringify(value) {
    try {
        return JSON.stringify(value);
    } catch (e) {
        return String(value);
    }
}

function appendDebugSe2010(message) {
    try {
        var prefix = &quot;[SE2010] &quot;;
        var atual = (hAPI.getCardValue(&quot;debug_publicacao&quot;) || &quot;&quot;) + &quot;&quot;;
        var linha = prefix + message;
        hAPI.setCardValue(&quot;debug_publicacao&quot;, atual ? (atual + &quot;\n&quot; + linha) : linha);
    } catch (e) {
        log.warn(&quot;appendDebugSe2010 falhou: &quot; + e);
    }
}
</eventDescription>
    </WorkflowProcessEvent>
    <WorkflowProcessEvent>
      <workflowProcessEventPK>
        <companyId>1</companyId>
        <eventId>beforeStateEntry</eventId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
      </workflowProcessEventPK>
      <eventDescription>function beforeStateEntry(sequenceId) {&#xd;
    appendDebugPublicacao(&quot;beforeStateEntry sequenceId=&quot; + sequenceId);&#xd;
&#xd;
    if (sequenceId == 7) {&#xd;
        anexarDocumentoDoCardSeNecessario();&#xd;
        publicarDocumento();&#xd;
    }&#xd;
&#xd;
    if (sequenceId == 7) {&#xd;
        var attachments = hAPI.listAttachments();&#xd;
        var hasAttachment = attachments &amp;&amp; attachments.size() &gt; 0;&#xd;
        appendDebugPublicacao(&quot;validacao anexos: total=&quot; + (attachments ? attachments.size() : 0));&#xd;
&#xd;
        if (!hasAttachment) {&#xd;
            appendDebugPublicacao(&quot;validacao anexos: nenhum anexo encontrado apos processamento.&quot;);&#xd;
            throw &quot;\n\nNao identificamos nenhum documento anexado, volte ao formulario e anexe pelo menos um documento para avancar a solicitacao.\n\n&quot;;&#xd;
        }&#xd;
    }&#xd;
}&#xd;
&#xd;
function anexarDocumentoDoCardSeNecessario() {&#xd;
    try {&#xd;
        var attachments = hAPI.listAttachments();&#xd;
        if (attachments &amp;&amp; attachments.size() &gt; 0) {&#xd;
            appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: solicitacao ja possui &quot; + attachments.size() + &quot; anexo(s).&quot;);&#xd;
            return;&#xd;
        }&#xd;
&#xd;
        var anexoIdStr = (hAPI.getCardValue(&quot;anexo_documento_id&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
        anexoIdStr = anexoIdStr.replace(/^\s+|\s+$/g, &quot;&quot;);&#xd;
        if (!anexoIdStr) {&#xd;
            appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: campo anexo_documento_id vazio.&quot;);&#xd;
            return;&#xd;
        }&#xd;
&#xd;
        var anexoId = parseInt(anexoIdStr, 10);&#xd;
        if (isNaN(anexoId) || anexoId &lt;= 0) {&#xd;
            appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: anexo_documento_id invalido: &quot; + anexoIdStr);&#xd;
            return;&#xd;
        }&#xd;
&#xd;
        hAPI.attachDocument(anexoId);&#xd;
        appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: hAPI.attachDocument OK documentId=&quot; + anexoId);&#xd;
&#xd;
        var attachmentsDepois = hAPI.listAttachments();&#xd;
        appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: total anexos apos attachDocument = &quot; + (attachmentsDepois ? attachmentsDepois.size() : 0));&#xd;
    } catch (e) {&#xd;
        appendDebugPublicacao(&quot;anexarDocumentoDoCardSeNecessario: ERRO &quot; + e);&#xd;
    }&#xd;
}&#xd;
&#xd;
function appendDebugPublicacao(msg) {&#xd;
    try {&#xd;
        var atual = (hAPI.getCardValue(&quot;debug_publicacao&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
        var prefix = atual ? atual + &quot;\n&quot; : &quot;&quot;;&#xd;
        hAPI.setCardValue(&quot;debug_publicacao&quot;, prefix + msg);&#xd;
    } catch (e) {&#xd;
        log.warn(&quot;appendDebugPublicacao falhou: &quot; + e);&#xd;
    }&#xd;
}&#xd;
</eventDescription>
    </WorkflowProcessEvent>
    <WorkflowProcessEvent>
      <workflowProcessEventPK>
        <companyId>1</companyId>
        <eventId>publicarDocumento</eventId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
      </workflowProcessEventPK>
      <eventDescription>function publicarDocumento() {&#xd;
    var radioGed = (hAPI.getCardValue(&quot;radio_ged&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
    var idPastaSelecionadaRaw = (hAPI.getCardValue(&quot;idPastaSelecionada&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
    log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## radio_ged=&quot; + radioGed + &quot; idPastaSelecionada=&quot; + idPastaSelecionadaRaw);&#xd;
    appendDebugPublicacao(&quot;publicarDocumento: radio_ged=&quot; + radioGed + &quot; idPastaSelecionada=&quot; + idPastaSelecionadaRaw);&#xd;
&#xd;
    if (radioGed != &quot;publica_ged&quot;) {&#xd;
        log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## Nao publicar no ECM (radio_ged diferente de publica_ged).&quot;);&#xd;
        appendDebugPublicacao(&quot;publicarDocumento: radio_ged diferente de publica_ged.&quot;);&#xd;
        return;&#xd;
    }&#xd;
&#xd;
    var attachments = hAPI.listAttachments();&#xd;
    log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## attachments.size=&quot; + (attachments ? attachments.size() : 0));&#xd;
    appendDebugPublicacao(&quot;publicarDocumento: attachments.size=&quot; + (attachments ? attachments.size() : 0));&#xd;
&#xd;
    for (var i = 0; i &lt; attachments.size(); i++) {&#xd;
        var docDto = attachments.get(i);&#xd;
        log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## analisando anexo documentId=&quot; + docDto.getDocumentId() + &quot; version=&quot; + docDto.getVersion() + &quot; documentType=&quot; + docDto.getDocumentType());&#xd;
        appendDebugPublicacao(&quot;publicarDocumento: analisando documentId=&quot; + docDto.getDocumentId() + &quot; version=&quot; + docDto.getVersion() + &quot; type=&quot; + docDto.getDocumentType());&#xd;
&#xd;
        try {&#xd;
            docAPI.copyDocumentToUploadArea(docDto.getDocumentId(), docDto.getVersion());&#xd;
&#xd;
            docDto.setDocumentId(0);&#xd;
&#xd;
            var idPastaSelecionada = parseInt((hAPI.getCardValue(&quot;idPastaSelecionada&quot;) || &quot;&quot;) + &quot;&quot;, 10);&#xd;
            if (isNaN(idPastaSelecionada) || idPastaSelecionada &lt;= 0) {&#xd;
                log.warn(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## idPastaSelecionada invalido. Documento nao sera publicado no ECM.&quot;);&#xd;
                appendDebugPublicacao(&quot;publicarDocumento: idPastaSelecionada invalido.&quot;);&#xd;
                continue;&#xd;
            }&#xd;
&#xd;
            docDto.setParentDocumentId(idPastaSelecionada);&#xd;
&#xd;
            var attachArray = new java.util.ArrayList();&#xd;
            var mainAttach = docAPI.newAttachment();&#xd;
            mainAttach.setFileName(docDto.getPhisicalFile());&#xd;
            mainAttach.setPrincipal(true);&#xd;
            mainAttach.setAttach(false);&#xd;
            attachArray.add(mainAttach);&#xd;
&#xd;
            docDto.setActiveVersion(true);&#xd;
            docDto.setColleagueId(getValue(&quot;WKUser&quot;));&#xd;
            docDto.setPublisherId(getValue(&quot;WKUser&quot;));&#xd;
&#xd;
            if (hAPI.getCardValue(&quot;radio_data_validade&quot;) == &quot;com_data_validade&quot;) {&#xd;
                docDto.setExpires(true);&#xd;
&#xd;
                if (hAPI.getCardValue(&quot;inicio_validade&quot;) != &quot;&quot;) {&#xd;
                    var inicioValidade = (hAPI.getCardValue(&quot;inicio_validade&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
                    var dataInicioSplit = inicioValidade.split(&quot;-&quot;);&#xd;
                    var anoInicio = dataInicioSplit[0];&#xd;
                    var mesInicio = parseFloat(dataInicioSplit[1]) - 1;&#xd;
                    var diaInicio = dataInicioSplit[2];&#xd;
                    var dInicio = new Date(anoInicio, mesInicio, diaInicio);&#xd;
                    docDto.setValidationStartDate(dInicio);&#xd;
                }&#xd;
&#xd;
                if (hAPI.getCardValue(&quot;expiracao_validade&quot;) != &quot;&quot;) {&#xd;
                    var dataVencimento = (hAPI.getCardValue(&quot;expiracao_validade&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
                    var dataSplit = dataVencimento.split(&quot;-&quot;);&#xd;
                    var ano = dataSplit[0];&#xd;
                    var mes = parseFloat(dataSplit[1]) - 1;&#xd;
                    var dia = dataSplit[2];&#xd;
                    var d = new Date(ano, mes, dia);&#xd;
                    docDto.setExpirationDate(d);&#xd;
                }&#xd;
&#xd;
                if (hAPI.getCardValue(&quot;dias_antes_expiracao&quot;) != &quot;&quot;) {&#xd;
                    var diasAntesExpiracao = parseInt(hAPI.getCardValue(&quot;dias_antes_expiracao&quot;), 10);&#xd;
                    docDto.setNotificationDays(diasAntesExpiracao);&#xd;
                }&#xd;
            } else {&#xd;
                docDto.setExpires(false);&#xd;
            }&#xd;
&#xd;
            log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## before create document&quot;);&#xd;
            var doc = docAPI.createDocument(docDto, attachArray, null, null, null);&#xd;
            log.info(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## DOCUMENTO CRIADO COM O ID: &quot; + doc.getDocumentId());&#xd;
            appendDebugPublicacao(&quot;publicarDocumento: documento publicado no ECM com id=&quot; + doc.getDocumentId());&#xd;
        } catch (e) {&#xd;
            log.error(&quot;PUBLICAR_DOCUMENTO LANCAMENTO_DOCUMENTO ########## falha ao publicar anexo documentId=&quot; + docDto.getDocumentId() + &quot; erro=&quot; + e);&#xd;
            appendDebugPublicacao(&quot;publicarDocumento: ERRO ao publicar documentId=&quot; + docDto.getDocumentId() + &quot; erro=&quot; + e);&#xd;
        }&#xd;
    }&#xd;
}&#xd;
&#xd;
function appendDebugPublicacao(msg) {&#xd;
    try {&#xd;
        var atual = (hAPI.getCardValue(&quot;debug_publicacao&quot;) || &quot;&quot;) + &quot;&quot;;&#xd;
        var prefix = atual ? atual + &quot;\n&quot; : &quot;&quot;;&#xd;
        hAPI.setCardValue(&quot;debug_publicacao&quot;, prefix + msg);&#xd;
    } catch (e) {&#xd;
        log.warn(&quot;appendDebugPublicacao falhou: &quot; + e);&#xd;
    }&#xd;
}&#xd;
</eventDescription>
    </WorkflowProcessEvent>
  </list>
  <list/>
  <list>
    <SwimLane>
      <color>FFFFFF</color>
      <height>611</height>
      <width>1401</width>
      <positionX>10</positionX>
      <positionY>10</positionY>
      <stateName>Lançamento de documento</stateName>
      <type>1</type>
      <parentSequence>0</parentSequence>
      <swimLanePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>1</sequence>
      </swimLanePK>
    </SwimLane>
    <SwimLane>
      <color>DBE8FF</color>
      <height>203</height>
      <width>1371</width>
      <positionX>40</positionX>
      <positionY>10</positionY>
      <stateName>Solicitante</stateName>
      <type>2</type>
      <parentSequence>1</parentSequence>
      <swimLanePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>2</sequence>
      </swimLanePK>
    </SwimLane>
    <SwimLane>
      <color>E2E2E2</color>
      <height>203</height>
      <width>1371</width>
      <positionX>40</positionX>
      <positionY>213</positionY>
      <stateName>Responsável por documentos</stateName>
      <type>2</type>
      <parentSequence>1</parentSequence>
      <swimLanePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>3</sequence>
      </swimLanePK>
    </SwimLane>
    <SwimLane>
      <color>82b0b7</color>
      <height>205</height>
      <width>1371</width>
      <positionX>40</positionX>
      <positionY>416</positionY>
      <stateName>SwimLane</stateName>
      <type>2</type>
      <parentSequence>1</parentSequence>
      <swimLanePK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>1</version>
        <sequence>6</sequence>
      </swimLanePK>
    </SwimLane>
  </list>
  <list/>
  <list/>
  <list>
    <ProcessLinkBend>
      <processLinkBendPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>13</version>
        <linkSequence>6</linkSequence>
        <bendSequence>1</bendSequence>
      </processLinkBendPK>
      <positionX>137</positionX>
      <positionY>279</positionY>
    </ProcessLinkBend>
    <ProcessLinkBend>
      <processLinkBendPK>
        <companyId>1</companyId>
        <processId>FlowEssentials_LancamentodeDocumento</processId>
        <version>13</version>
        <linkSequence>16</linkSequence>
        <bendSequence>1</bendSequence>
      </processLinkBendPK>
      <positionX>332</positionX>
      <positionY>520</positionY>
    </ProcessLinkBend>
  </list>
  <list/>
  <list/>
  <list/>
  <list>
    <ProcessStateService>
      <companyId>1</companyId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <version>1</version>
      <sequence>15</sequence>
      <attempts>0</attempts>
      <sucessFullMessage>Integração executada com sucesso</sucessFullMessage>
      <serviceName>FlowEssentials_LancamentodeDocumento.servicetask15</serviceName>
      <frequency>1</frequency>
      <frequencyType>0</frequencyType>
    </ProcessStateService>
  </list>
  <list/>
  <list>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>5</stateSequence>
      <appKey>approval</appKey>
      <appField>title</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>5</stateSequence>
      <appKey>approval</appKey>
      <appField>description</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>5</stateSequence>
      <appKey>approval</appKey>
      <appField>highlight</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>5</stateSequence>
      <appKey>approval</appKey>
      <appField>approve</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>5</stateSequence>
      <appKey>approval</appKey>
      <appField>reject</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>22</stateSequence>
      <appKey>approval</appKey>
      <appField>title</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>22</stateSequence>
      <appKey>approval</appKey>
      <appField>description</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>22</stateSequence>
      <appKey>approval</appKey>
      <appField>highlight</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>22</stateSequence>
      <appKey>approval</appKey>
      <appField>approve</appField>
      <description></description>
    </ProcessAppConfiguration>
    <ProcessAppConfiguration>
      <id>0</id>
      <tenantId>0</tenantId>
      <processId>FlowEssentials_LancamentodeDocumento</processId>
      <processVersion>13</processVersion>
      <stateSequence>22</stateSequence>
      <appKey>approval</appKey>
      <appField>reject</appField>
      <description></description>
    </ProcessAppConfiguration>
  </list>
  <list/>
  <list/>
</list>