• +351 91 33 888 29
    • clico@clico.pt

    Category Archive PowerPlataform

    Espelhar listas de Sharepoint com Power Automate

    Guia Prático: Espelhar Todas as Listas do SharePoint com Power Automate

    Espelhar Listas SharePoint com Power Automate (Multi-Ambiente)

    Espelhar Listas SharePoint com Power Automate (Multi-Ambiente)

    Quer espelhar listas SharePoint e manter todas as listas dos seus sites de destino com o mesmo esquema (colunas) que as listas de um site de origem? Neste guia mostro o flow que uso para:

    • Percorrer todas as listas e bibliotecas do site de origem;
    • Criar a lista/biblioteca no destino se ainda não existir;
    • Comparar campos (por InternalName) e criar automaticamente os que faltam;
    • Lidar com vários destinos (ambientes diferentes) para espelhar listas SharePoint com consistência;
    • Tratar Lookups com mapeamento por ambiente.

    Sem conectores premium, apenas Send an HTTP request to SharePoint e ações standard. 👇

    Quando usar (e quando não)

    Use quando precisa de espelhar listas SharePoint para manter consistência de esquema entre ambientes (Dev/Test/Prod) sem trabalho manual.

    Não use para migrar dados (linhas) nem para tipos muito específicos como Managed Metadata complexos — podem ficar para uma fase 2.

    Arquitetura do Flow para espelhar listas SharePoint

    • Trigger: Recurrence (ex.: de hora a hora).
    • Origem: 1 site SharePoint.
    • Destino(s): 1..N sites SharePoint.
    • Estratégia:
      1. Listar todas as listas/bibliotecas visíveis na origem;
      2. Para cada destino:
        • Garantir que a lista/biblioteca existe (cria se faltar);
        • Obter campos da origem (apenas custom);
        • Obter campos do destino;
        • MissingFields = origem − destino;
        • Criar MissingFields com POST à API (sem XML) — e XML/ajustes só quando necessário (Lookup, etc.).

    Pré-requisitos

    • Conta de serviço com permissões para ler e alterar esquema nos sites de origem e destino(s).
    • Conector Send an HTTP request to SharePoint configurado nos tenants necessários.
    • Naming consistente de listas (ou use o caminho server-relative).

    Variáveis base (Initialize)

    • SourceSiteUrl (String) → URL do site origem
      Ex.: https://<tenant>.sharepoint.com/sites/Origem
    • TargetSites (Array) → destinos + (opcional) mapas por ambiente:
    [
      {
        "siteUrl": "https://<tenantA>.sharepoint.com/sites/DestinoA",
        "lookupMap": {
          "ClienteId": { "TargetListServerRelativeUrl": "/sites/DestinoA/Lists/Clientes" }
        }
      },
      {
        "siteUrl": "https://<tenantB>.sharepoint.com/sites/DestinoB",
        "lookupMap": { }
      }
    ]
    • CurrentSiteUrl (String) = ""
    • CurrentListTitle (String) = ""
    • CurrentLookupMap (Object) = {}
    • TargetInternalNames (Array) = []

    Dica: pode guardar TargetSites num ficheiro JSON numa biblioteca e lê-lo com “Get file content”.

    Passo 1 — Listar listas/bibliotecas na origem

    HTTP (GET) – Get_All_Lists

    • Site Address: @{variables('SourceSiteUrl')}
    • Headers: Accept: application/json;odata=nometadata
    • URI:
    _api/web/lists?$select=Title,BaseTemplate,Hidden,RootFolder/ServerRelativeUrl,Id
    &$expand=RootFolder
    &$filter=(Hidden eq false) and ((BaseTemplate eq 100) or (BaseTemplate eq 101))
    &$top=5000

    Apply to each – ForEach_SourceLists
    From@{body('Get_All_Lists')?['value']}

    • Compose – SourceListTitle@{items('ForEach_SourceLists')?['Title']}
    • Compose – SourceListUrl@{items('ForEach_SourceLists')?['RootFolder']?['ServerRelativeUrl']}

    BaseTemplate 100 = Lista; 101 = Biblioteca. Adicione outros se precisar.

    Passo 2 — Para cada destino

    Apply to each – ForEach_TargetSites
    From@{variables('TargetSites')}

    • Set var – CurrentSiteUrl@{items('ForEach_TargetSites')?['siteUrl']}
    • Set var – CurrentLookupMap@{items('ForEach_TargetSites')?['lookupMap']}
    • Set var – CurrentListTitle@{outputs('SourceListTitle')}

    2.1 Garantir que a lista existe

    HTTP (GET) – Get_Target_List_By_Title

    • Site: @{variables('CurrentSiteUrl')}
    • Headers: Accept: application/json;odata=nometadata
    • URI:
    _api/web/lists?$filter=Title eq '@{replace(variables('CurrentListTitle'),'''','''''')}'
    &$select=Id,Title,BaseTemplate&$top=1

    Condition – ListExists@greater(length(body('Get_Target_List_By_Title')?['value']), 0)

    If NO → HTTP (POST) – Create_List

    • Site: @{variables('CurrentSiteUrl')}
    • Headers: Accept: application/json;odata=verbose + Content-Type: application/json;odata=verbose
    • URI: _api/web/lists
    • Body (Expression):
    @json(
      concat(
        '{"__metadata":{"type":"SP.List"},"Title":"',
        replace(variables('CurrentListTitle'),'"','\"'),
        '","BaseTemplate":',
        string(items('ForEach_SourceLists')?['BaseTemplate']),
        ',"AllowContentTypes":true,"ContentTypesEnabled":true}'
      )
    )

    Se preferir criar por caminho (para bibliotecas com nomes localizados), também pode usar _api/web/folders + RootFolder (extra opcional).

    Passo 3 — Obter campos da origem (custom)

    HTTP (GET) – Get_Source_Fields

    • Site: @{variables('SourceSiteUrl')}
    • Headers: Accept: application/json;odata=nometadata
    • URI:
    _api/web/GetList(@listUrl)/Fields
    ?$select=Title,InternalName,TypeAsString,SchemaXml,Hidden,ReadOnlyField,Sealed,FromBaseType,CanBeDeleted,Required
    &@listUrl='@{outputs('SourceListUrl')}'

    Filter array – Keep_Custom_Fields
    From: @{body('Get_Source_Fields')?['value']}

    @and(
      equals(item()?['Hidden'], false),
      equals(item()?['FromBaseType'], false),
      equals(item()?['Sealed'], false),
      equals(item()?['ReadOnlyField'], false)
    )

    Select – Project_Source_Fields
    From: @{body('Keep_Custom_Fields')}
    Map: InternalName, Title, TypeAsString, Required, SchemaXml.

    Passo 4 — Obter campos do destino & calcular “MissingFields”

    • Set var – TargetInternalNames[] (limpar)

    HTTP (GET) – Get_Target_Fields

    • Site: @{variables('CurrentSiteUrl')}
    • Headers: Accept: application/json;odata=nometadata
    • URI:
    _api/web/lists/getbytitle('@{replace(variables('CurrentListTitle'),'''','''''')}')
    /Fields?$select=InternalName

    Apply to each – ForEach_TargetFields
    From: @{body('Get_Target_Fields')?['value']}
    Append to array – TargetInternalNames = @{item()?['InternalName']}

    Filter array – MissingFields
    From: @{body('Project_Source_Fields')}

    @not(contains(variables('TargetInternalNames'), item()?['InternalName']))

    Este passo assegura que consegue espelhar listas SharePoint criando apenas os campos em falta.

    Passo 5 — Criar MissingFields

    Apply to each – CreateMissingFields
    From: @{body('MissingFields')}

    Switch – On@{items('CreateMissingFields')?['TypeAsString']}

    Cabeçalhos e Endpoint (iguais em todos os cases)

    • Site Address: @{variables('CurrentSiteUrl')}
    • URI: _api/web/lists/getbytitle('@{replace(variables('CurrentListTitle'),'''','''''')}')/Fields
    • Headers:
      • Accept: application/json;odata=verbose
      • Content-Type: application/json;odata=verbose

    Bodies como Expression (@json(concat(...)))

    Text

    @json(concat('{"__metadata":{"type":"SP.FieldText"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":2,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"MaxLength":255}'))

    Note (multilinha)

    @json(concat('{"__metadata":{"type":"SP.FieldMultiLineText"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":3,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"NumberOfLines":6,"RichText":false,"AppendOnly":false}'))

    Number

    @json(concat('{"__metadata":{"type":"SP.FieldNumber"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":9,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),'}'))

    DateTime

    @json(concat('{"__metadata":{"type":"SP.FieldDateTime"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":4,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"DisplayFormat":0}'))

    Boolean

    @json(concat('{"__metadata":{"type":"SP.FieldBoolean"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":8,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"DefaultValue":"0"}'))

    User

    @json(concat('{"__metadata":{"type":"SP.FieldUser"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":20,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"AllowMultipleValues":false,"SelectionMode":0}'))

    URL

    @json(concat('{"__metadata":{"type":"SP.FieldUrl"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":11,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"DisplayFormat":0}'))

    Choice (ajuste as opções)

    @json(concat('{"__metadata":{"type":"SP.FieldChoice"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":6,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"Choices":{"results":["Opção 1","Opção 2","Opção 3"]},"EditFormat":0}'))

    MultiChoice

    @json(concat('{"__metadata":{"type":"SP.FieldMultiChoice"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":15,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"Choices":{"results":["A","B","C"]},"FillInChoice":false}'))
    Precisa de ajuda

    Lookup / LookupMulti

    1. HTTP (GET) – GetRefListId
      Site: @{variables('CurrentSiteUrl')}  |  Headers: Accept: application/json;odata=nometadata
      URI (por caminho, usando CurrentLookupMap):
    _api/web/GetList(@listUrl)?$select=Id
    &@listUrl='@{variables('CurrentLookupMap')?[items('CreateMissingFields')?['InternalName']]?['TargetListServerRelativeUrl']}'

    Compose – RefListId@{body('GetRefListId')?['Id']}

    Lookup (simples)

    @json(concat('{"__metadata":{"type":"SP.FieldLookup"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":7,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"LookupList":"{',outputs('RefListId'),'}","LookupField":"Title","AllowMultipleValues":false}'))

    LookupMulti

    @json(concat('{"__metadata":{"type":"SP.FieldLookup"},"Title":"',replace(items('CreateMissingFields')?['Title'],'"','\"'),'","StaticName":"',items('CreateMissingFields')?['InternalName'],'","FieldTypeKind":7,"Required":',if(items('CreateMissingFields')?['Required'],'true','false'),',"LookupList":"{',outputs('RefListId'),'}","LookupField":"Title","AllowMultipleValues":true}'))

    Se não existir entrada no CurrentLookupMap para aquele campo → não substitua (crie como simples) ou salte com log.

    Boas práticas (o que funciona melhor)

    • Compare por InternalName, não por Title.
    • Faça escape de apóstrofos em getbytitle: replace(..., '''', '''''').
    • Prefira GetList(@listUrl) para bibliotecas/nomes localizados.
    • Controle de concorrência no loop de criação (1–3) para evitar throttling.
    • Crie logs (site/lista/campo/resultado) numa lista “AdminLogs”.
    • Use guard-rails: Conditions para só tratar Lookup quando houver lookupMap.
    • Faça um teste “seco”: primeiro calcule os MissingFields e escreva log; depois ative a criação para realmente espelhar listas SharePoint nos destinos.

    Limitações & extensões

    • Managed Metadata (Taxonomia) e Calculated complexos: recomendo criar via SchemaXml (ou PnP/CLI) numa segunda fase.
    • Renomeações (Title): para sincronizar títulos, adicione um PATCH/MERGE para .../Fields/getbyinternalnameortitle('INTERNAL') com "Title":"Novo Título".
    • Content Types: em ambientes com content types partilhados, pode ser preferível publicar/associar content types em vez de mexer diretamente em cada lista.

    Conclusão

    Com este flow passa a espelhar listas SharePoint e garantir governança de esquema: qualquer lista nova/alterada na origem é replicada para todos os destinos, sem cliques manuais. A peça-chave é usar a API do SharePoint para listar, comparar e criar campos de forma segura, com variações para Lookups e bibliotecas.

    PowerApps: O Manual Essencial para Criar Apps de Forma Fácil e Transformadora

    Como começar com PowerApps: Manual Simples para Iniciantes em TI

    Se é da área de TI, provavelmente já sentiu a pressão para criar soluções rápidas, mesmo sem ter muita experiência em programação. Felizmente, plataformas como o PowerApps surgiram para simplificar a sua vida.

    Este manual simples é para si, que tem pouco conhecimento de programação, mas quer começar rapidamente a criar aplicações com ferramentas low-code.

    O que é o PowerApps e porque é importante?

    O PowerApps é uma plataforma da Microsoft concebida para simplificar o desenvolvimento de aplicações sem necessidade de conhecimentos aprofundados em programação. É ideal para profissionais de TI que desejam entregar soluções práticas, rápidas e eficazes, sem depender de equipas especializadas.

    A importância do PowerApps está na facilidade de utilização e na possibilidade de ligação a vários serviços e dados, como SharePoint, Excel, Azure e Dynamics 365. Isso permite automatizar tarefas, digitalizar processos e aumentar a produtividade com pouco código.

    Como criar a sua primeira aplicação no PowerApps

    1. Aceda à plataforma: Vá ao site do PowerApps e inicie sessão com a sua conta Microsoft.

    2. Escolha um modelo: Para iniciantes, a Microsoft oferece vários modelos pré-configurados. Escolha o que estiver mais próximo do que precisa.

    3. Personalize a aplicação: Utilize a interface intuitiva para adicionar controlos como botões, formulários e galerias. Arraste e largue componentes visuais com facilidade.

    4. Ligue os seus dados: Integre fontes de dados como Excel ou SharePoint. O PowerApps facilita o acesso e utilização dessas informações diretamente na sua aplicação.

    5. Teste e publique: Use o modo de visualização para testar o funcionamento. Quando estiver pronto, publique e partilhe com colegas.

    Dicas práticas para iniciantes no PowerApps

    • Comece de forma simples: Evite criar soluções complexas logo no início. Ganhe confiança com aplicações básicas.

    • Explore tutoriais: A Microsoft disponibiliza muitos recursos gratuitos para acelerar a sua aprendizagem.

    • Experimente e erre: Não tenha receio de testar. Quanto mais experimentar, mais rapidamente aprenderá.

    Exemplos reais de utilização

    O PowerApps já ajudou profissionais de TI sem experiência em programação a desenvolver:

    • Aplicações para registo de entrada e saída de funcionários.

    • Sistemas simples de gestão de inventário.

    • Ferramentas de pesquisa e feedback de clientes.

    Estas soluções trouxeram melhorias rápidas e visíveis para as empresas, mostrando que o poder da inovação está ao alcance de todos, e não apenas dos especialistas.

    Conclusão

    Dominar o PowerApps é acessível mesmo para quem tem pouco ou nenhum conhecimento técnico aprofundado. Com dedicação e prática, poderá criar aplicações úteis e eficazes para resolver problemas quotidianos na sua empresa.

    Comece já hoje a explorar o potencial do desenvolvimento low-code com o PowerApps e veja como pode transformar a forma como a sua empresa trabalha.

    Se precisar de consultoria especializada ou ajuda no desenvolvimento da sua aplicação, não hesite em contactar-nos. Estamos aqui para ajudar e acelerar os seus resultados com PowerApps.

    Contacte-nos

    Ilustração simples sobre PowerApps para iniciantes em TI
    Ilustração simples sobre PowerApps para iniciantes em TI
    Categorize Email

    Power Automate – Categorize Email

    Temos um Use Case para categorizar um email. Temos uma caixa partilhada, onde são recebidos vários emails que várias pessoas os tratam. Toda a informação é guardada numa lista de sharepoint (no caso) e com um sistema de Ticketing tool, conseguimos associar um email se for novo a uma pessoa que esteja na lista de disponível ou se existir a quem já o trata.

    No fluxo, onde está: “environment variable”, colocam a caixa de correio pretendida.

    Body ID vem da mensagem que recebe no início do fluxo, que é o que despoleta o correr do fluxo.

    URI: https://graph.microsoft.com/v1.0/users/”environment variable”/mailFolders/Inbox/messages/@{triggerOutputs()?[‘body/id’]}

    Method: Patch

    Body: {
    “categories”: [“Orange Category”]
    }

    Deixo como categorizar o mesmo, para as restantes condições, contacte-nos pelos nossos meios.

    Categorize Email

    DateTimeValue Function

    Converter datas é um desafio e ter uma função que faz isso, facilita-nos bastante o trabalho.
    A função DateTimeValue faz isso por nós. A função converte uma string num objeto de data e hora.

    DateTimeValue("2024-10-01")
    
    retornará:
    
    01-10-2024 00:00
    Date TimeValue
    Experimentemos utilizar com hora:
    DateTimeValue("2024-10-01 16:00")

    retornará:
    01/10/2024 16:00
    Date time Value with Hour
    Date and Time Function

    How to rotate images in Powerapps

    • Create a New Screen :
      • In your Power App, go to the “Screens” tab.
      • Click on “New Screen” and choose a blank screen template or any other layout that suits your design.
    • In New Screen insert image (Ex.:”image1″)
    • In New screen Insert Icon “Reload” (Ex. “iconrotate”)
    • On New screen property “On Visible”, set it:
      • Set(
            iRotate,
            0
        );
        Set(
            stRotate,
            “ImageRotation.None”
        );
    • On image “image1” property “ImageRotation”, set: 
      • stRotate
    • On icon  “iconrotate” property “OnSelect”, set:
      • If(
            iRotate < 3,
            Set(
                iRotate,
                iRotate + 1
            ),
            Set(
                iRotate,
                0
            )
        );
        Switch(
           iRotate,
           1,
           Set(
              stRotate,
              “rotate90”
           ),
           2,
           Set(
              stRotate,
              “rotate180”
           ),
           3,
           Set(
              stRotate,
              “rotate270”
           ),
           Set(
              stRotate,
              “ImageRotation.None”
           )
        )

    PowerApps – Best Practices

    PowerApps - Best Practices

    PowerApps is a versatile platform for building custom business apps that can connect to various data sources and services. To ensure that your PowerApps projects are efficient, maintainable, and scalable, it’s important to follow best practices. Here are some PowerApps best practices to consider:

    1. Plan Your App: Before you start building your app, take the time to plan it out. Define the app’s purpose, requirements, and user needs. Create a design and data architecture plan to guide your development.

    2. Use App Templates: PowerApps provides pre-built templates for common app scenarios. Consider using these templates as a starting point to save time and ensure you follow best practices.

    3. Responsive Design: Design your app to be responsive so it works well on various screen sizes and devices. Use layout containers and flexible design elements.

    4. Separation of Concerns: Follow the Model-View-Controller (MVC) or Model-View-ViewModel (MVVM) pattern to separate your app’s data, user interface, and logic. This makes your app more maintainable and easier to test.

    5. Use Custom Connectors: If you need to connect to external services or data sources, consider creating custom connectors. Custom connectors offer better performance and can be reused across multiple apps.

    6. Optimize Data Loading: Avoid loading unnecessary data. Use filters, delegation, and data shaping functions like Sort and Filter to fetch only the data you need. Delegation ensures that data processing happens on the data source side rather than in PowerApps, which can improve performance.

    7. Error Handling: Implement robust error handling to provide a better user experience. Use the Error function to capture and display meaningful error messages to users.

    8. Testing and Debugging: Test your app thoroughly during development. Use the built-in debugging tools to identify and fix issues. Also, involve end-users in testing to gather feedback.

    9. Version Control: Use version control systems like GitHub to track changes to your app’s code. This helps in collaboration and rollback in case of issues.

    10. Documentation: Document your app’s design, data sources, and functionality. This documentation is valuable for future maintenance and for onboarding new team members.

    11. Security: Implement appropriate security measures. Use Azure Active Directory for authentication and authorization. Limit access to sensitive data and functionality based on user roles.

    12. Performance Optimization: Optimize your app for performance by minimizing the number of calls to external data sources and avoiding complex formulas when possible. Use collections to store and manipulate data locally.

    13. User Training: Provide training and support for app users. Make sure they understand how to use the app effectively.

    14. Monitor and Analyze: Use Power Platform’s built-in monitoring and analytics tools to track app usage, identify performance bottlenecks, and gather insights for improvements.

    15. Stay Informed: Stay updated with the latest PowerApps features, updates, and best practices by regularly checking Microsoft’s official documentation and community forums.

    Remember that best practices can evolve over time as the PowerApps platform and your organization’s needs change. Regularly review and update your practices to ensure your apps remain efficient and effective.

     

     
     
    Create popup messagebox in powerapp

    Create a Popup message box in Powerapp Canva

    Create a popup message box

    1. Create a New Screen :
      • In your Power App, go to the “Screens” tab.
      • Click on “New Screen” and choose a blank screen template or any other layout that suits your design.
    2. Design the Popup :
      • On the new screen, design your popup box. You can use container and add labels, buttons, input controls, or any other elements you need for your popup’s content. 
    3. Create a Button or Trigger to Show the Popup :
      • On the screen (or wherever you want to trigger the popup), create a button or control (eg, an icon).
      • In the “OnSelect” property of the button, set it to navigate to the popup screen and make it visible:
          • Set(PopupVisible, true);
    4. Create a Close Button:
      • On the popup screen, create a close button (e.g., an “X” icon or a “Close” button).
      • In the “OnSelect” property of the close button, set it to navigate back to the previous screen and hide the popup:
          • Set(PopupVisible, false);
    5. Use a Variable for Visibility:
      • Create a variable to control the visibility of the popup. In the app’s OnStart or OnVisible property, initialize the variable:
          • Set(PopupVisible, false);
      • Set the “Visible” property of the popup screen to the value of the variable:
          • PopupVisible

                    Test Your Popup:

      • Preview or publish your Power App and test the popup functionality.
    Advertisements
    Show Buttons
    Hide Buttons