Sharing my Power Automate flow: Get query results using the new Query connectors!

Options
24

Comments

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Advancement Division
    A 2nd post to talk about CSV output format.

    There are a few reason to use CSV as output format rather than JSON:

    1. csv is itself already a file type that can open in excel, so sometime you may just want to send a csv (as an excel report) as attachment in email.
      1. Or you may want to save the CSV directly to SharePoint or cloud location, this is useful if you have Power BI build that refresh from a CSV file on SharePoint
    2. TOO MUCH data. Power Automate has a data size limit, so depending on how many rows of data and column of data, you may exceed that limit. https://learn.microsoft.com/en-us/power-automate/limits-and-config#request-limits
      1. Since a JSON output format will take up more BYTE than CSV for the same amount of rows/column of data
    b0fc43d797c617b4cda6ba09d453a843-huge-im

    so if you did use CSV output format, you can turn the CSV data into JSON easily with the Select action.

    skip(split(trim(replace(replace(base64ToString(body('HTTP_Get_Query_Result_CSV')?['$content']), '",','|'), '"', '')), outputs('Compose_New_Line')), 1)

    so the expression starts (meaning the inner most expression) with the base64ToString (same as JSON output), then there are 2 replace(): (1) replace “, with a separator character that is unlikely to be real data (i.e. pipeline character |); (2) replace with empty string.

    So for example, the CSV data of:
    “123”,"John Smith","Male","123 Main St."

    to (first replace)
    “123|”John Smith|"Male|"123 Main St."

    to (2nd replace)
    123|John Smith|Male|123 Main St.

    Then the trim() will remove any leading or trailing whitespace

    Then the split() will split the CSV by a new line character. (which I had a compose action that have 1 character in it, “enter” key, which is a newline character), this creates an array of string (i.e. 123|John Smith|Male|123 Main St.) that will be used in the Select action.

    finally skip() will skip the first line in the data (which is the header row of the CSV.

    the “map” field of the Select action will create the JSON properties you want from the CSV.

    so the first column is the name of the property in JSON that can be referenced as dynamic content as subsequent actions.

    the 2nd column is the value, which are:
    split(item(), '|')?[0]
    split(item(), '|')?[1]
    split(item(), '|')?[2]
    etc

    so basically will use the split() expression on each string in the array (i.e. 123|John Smith|Male|123 Main St.), split by the pipeline character, and then accessing each element by an index.

    123|John Smith|Male|123 Main St. becomes an array of
    ["123","John Smith","Male","123 Main St."]

    [0] is the first element which is “123”
    [1] is the 2nd element which is “John Smith”
    etc

    Good luck.

    WARNING: the above expression will have issue when you have data that have “new line” character in the column. (i.e. Address lines, which has more than 1 line of address)

  • Is anybody experiencing mixed date formats in a created file? I'm UK based and half are coming through with UK gift date format, half with US gift date format. This seems to be a Power BI related problem, opening the export in Excel, all looks good, opening the data in Power Query causes the mixed date formats to show.

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Shaun Germany
    not sure what you meanb y mixed date format. please use example.

    you should check from the “source” to see where the issue is. Meaning, start with your Query API right after getting the CSV file (or JSON), what does the output look like.

  • @Alex Wong
    Hi Alex, UK date format dd/mm/yyyy 17/12/2024, US date format mm/dd/yyyy 12/17/2024. The output file “looks ok”, but not when Im trying to get that into/used by Power BI. Power BI actually sees the dates as “Text” which I tried to transform into a date.

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Shaun Germany
    not sure what you mean by “looks ok”. So in the download data after execute query, the 2 date format exists or they are uniformly 1 date format? if 2 format, which field is UK vs US?

    Power BI does have a “regional setting” so you will want to confirm that, otherwise, you will do some Power Query to transform the data which shouldn't be too difficult.

  • @Shaun Germany- Hi Shawn- YES I have been experiencing this lately and I thought it was just me. In Power BI, I have a table of data and I go to copy the table into Excel and it is not a date. It comes over as text. The settings in Power BI have it set to date data type. It comes over in Excel as the full day like today would be Wednesday, December 18, 2024. I can't change the format to a date like I used to. Is this the same issue you are having?

    I think this is an Excel issue but very annoying that I can't change it to Date once in Excel without a formula.

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Carol Grant
    Don't think it's the same issue as yours.

    It sounds like you are copying from PBI into excel. you need to update the format of the date in Power BI such that it is in the format you want. By default, it will always be Weekday, Month day, year.

    d7e9e5223f2c5222c72611e76bb9bb40-huge-im

    Instead change it to

    f18031402893cca5f5b1f9b39b5eaab2-huge-im
  • @Alex Wong
    I'm not 100% sure how I've fixed it tbh. I ended up starting from scratch and now it works. About the only thing I'm unsure of is when originally importing to Power Bi I'd maybe selected “Excel” whereas this time I selected “Text/CSV”. Whatever I'd done, by the time I got to Power Query/Transform data it was too late to do any of the obvious changes.

  • @Ashley Moose Thank you, Ashley! Successfully imported this template using RE Query API. Now, I am trying to figure out how to simply have the results of the query emailed to me rather than creating the csv file? So far, I have only gotten the gift ids emailed to me? Thanks for any suggestions on how to switch out the “save csv file” to emailing the query results.

  • Hi @Sandra Ross - Do you want the results emailed to you as an attachment or the entire result set emailed as a table?

  • @Ashley Moose Thanks for responding. Eventually want to learn both ways but for now, entire results set emailed as a table in the body of email. I thought I heard in one of the videos I've watched that this can be done without having to get each part of the body as we did using Get List.

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Sandra Ross
    if you want HTML table in the email body directly, then you will want to set the output format as JSON, as the action to create html table intakes a JSON Array. There are many templates relating to dailiy gift digest/notification or large gift notification that has actions to turn an array into html table and then add to email, here's one:

    https://community.blackbaud.com/forums/viewtopic/586/63853

    if you want to do excel attachment, you can always just attach the CSV, which you can simply take the “content” from the download and add to the email attachment content. CSV file is easily open in excel.

    however, if you want excel, there are a few ways to turn CSV into Excel and attach to email, as well as faster / slower way of doing so.

    https://community.blackbaud.com/forums/viewtopic/586/63726 - intake a CSV (template takes CSV from FTP, but same idea for Query API downloaded CSV) and turn into Excel file, does not have to save to Sharepoint, can be attached to email

    https://community.blackbaud.com/forums/viewtopic/426/65782 - a template that shows you how to fast save to excel, this is more advanced. Once you have the excel, then attaching to email is simple.

  • @Sandra Ross To add onto everything Alex shared, I'm also sharing a sample Flow that retrieves the query results as JSON. Currently in the FENXT Query Connector you can choose JSON as an output option, but this is missing in the RENXT Query Connector (it is in the works for that to be updated). You can still select JSON as the output using the Send an HTTP request actions though, as I've done in the attached flow.

    GetQueryTemplateasJSON_20241216202752.zip

  • @Ashley Moose I get an error when trying to import the solution into Power automate “The compressed file must contain the following files at its root: solution.xml, customizations.xml, and [Content_Types].xml.”
    Some files are missing, or am I doing something wrong?

  • Hi @Patrice Obertelli - I just tested the file and confirmed the import worked. Please make sure you are importing the entire .zip file using the Import Package option.

    36906d565d61333932fece20319d1bd3-huge-im
  • @Ashley Moose That must a question of version then, I don't have the option of “import (legacy)” only “ import solution”. I know a lot of options are disabled by our IT dept. I'll look into it. Thank you for your help.

  • @Ashley Moose I created an ad hoc query using the RENXT Query Connector, and I am trying to utilize the data without creating a csv, as all the responses are on one line for one constituent. This is the output I get when I view the output of the body of the response:

    {

    "$content-encoding": "cp1252",

    "$content-type": "text/csv",

    "$content": "Y2Z5QW1vdW50LGNmeUNvdW50LHBmeUFtb3VudCxwZnlDb3VudCwycGZ5QW1vdW50LDJwZnlDb3VudCxyZWN1ckFtb3VudCxyZWN1ckNvdW50LFFSRUNJRA0KIiQ3NSw1MDAuMDAiLCIyIiwiJDc1LDY1MC4wMCIsIjMiLCIkNzUsNTAwLjAwIiwiMiIsIiQ1MDAuMDAiLCIxIiwiNDU0MiI="

    }

    And when I display the body results on screen, I see this:

    cfyAmount,cfyCount,pfyAmount,pfyCount,2pfyAmount,2pfyCount,recurAmount,recurCount,QRECID "$75,500.00","2","$75,650.00","3","$75,500.00","2","$500.00","1","4542"

    How can I get this into a working format to call on these data points? I feel like I am missing something obvious!!

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Ryan Carr
    if you plan on using the Query API output directly in the flow, then JSON output is best, but you can't do that with the RE NXT Query Connector, you will need to use the Blackbaud SKY Add-in connector's Send Http request action to run your ad-hoc query.

    In one of my response in this post, (the long one with a lot of screenshot), I explained how you can use the $content property directly from the HTTP action that does the download (without first using a “Compose” action). (base64ToString() is your friend here).

    so right after the HTTP download action, you can do a Parse JSON action, and the input will be the expression: base64ToString(body('HTTP_Get_Query_Result')?['$content']) assuming your HTTP download action is named “HTTP Get Query Result”. The schema is going to depend on your output column.

  • @Alex Wong Thanks! I ended up using the Send HTTP Request and making the output JSON. I will try this other method out as well.

  • @Ryan Carr @Alex Wong fwiw in case it helps…Blackbaud is in the process of releasing an update to the Query connector for RENXT that includes both JSON/CSV output options. Updating connectors involves some coordination with Microsoft (they handle the actual deployment), and it can take some days/weeks to get through the process).

  • @Ashley Moose
    Thanks for the template. I would like to import it, but as my school is a Google shop, I don't have One Drive for Business or Office365 Outlook. So, I can't connect them while importing the flow. Do you have any suggestions? I am not good enough to open JSON and edit the flow with GMail and Google Drive connections before importing your template.

  • @July Choi Let me recreate it using a Google Drive connection and I'll post the updated flow(s) here tomorrow.

  • Hi @July Choi - The original post has been updated to include templates for FENXT and RENXT using Google Drive/Gmail. Please be aware that I received a notification after saving the flow that all features may not be available due to using a consumer gmail account (as opposed to a Google Workspace account). This link provides more information on how to resolve the issue if using that type of account.

  • @Ashley Moose / @Alex Wong

    If my query results are 0, I don't want a CSV saved - how do I go about that?

    I have some queries I run monthly for data audits and if people do their jobs correctly, the results are 0 ?

  • Hi @Kacie Wise - Since there isn't a count value returned, we'll need to read through the Content to see if there are actual records.

    1. On the Create File branch after HTTP-Get query results, add 3 Compose actions (before Create File).

    • Rename the first Compose action to FileContent and set the input to the following expression: replace(string(body('HTTP_-_Get_query_results')),'"','')
    • Rename the second Compose action to LineEnding and set the input to the following expression: if(equals(indexof(outputs('FileContent'), decodeUriComponent('%0D%0A')), -1), if(equals(indexof(outputs('FileContent'), decodeUriComponent('%0A')), -1), decodeUriComponent('%0D'), decodeUriComponent('%0A')), decodeUriComponent('%0D%0A'))
    • Rename the last Compose action to RemoveHeader and set the input to the following expression:

    2. After the last Compose action, add a new Condition action with the following criteria:

    length(outputs('RemoveHeader')) is greater than or equal 1

    3. Then on the If Yes branch, drag in your Create File action.

    5d306f24b903a9f981bf2a75e02ed1f4-huge-im
  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Kacie Wise
    Assuming your download action is named “HTTP Get Query Result CSV”

    Assuming you have a Compose action name “Compose New Line" where the content is just a newline character

    You can condition and check if your CSV has data by:

    length(split(trim(base64ToString(body('HTTP_Get_Query_Result_CSV')?['$content'])), outputs('Compose_New_Line'))) greater than 1.

    56b136e8f53972952a1c1bce94a73953-huge-im
    new line character, meaning enter a “Enter” key in Inputs
    c07a735fc889dc73917a58e7cf18aadd-huge-im
    d1475b67a103a7318d60b3e9eb42f0c1-huge-im
  • @Kacie Wise I just noticed while testing a different query that Row Count is being returned. So instead of going through everything @Alex Wong and I just shared, you can use

    outputs('Get_query_job_status')?['body/row_count']

    to reference the row count and then add that to the Condition - Get query results if completed, or add a new Condition under that one if you want to receive a different email response based on the actual results.


  • @Ashley Moose @Alex Wong thank you both SO much! this is going to speed up my monthly auditing A TON. ?

  • @Alex Wong I've just started looking at this again. And your solution was what I assumed I'd need to do, but I've so far not got it to work. The column containing the dates has some cells are formatted to a “Custom Date” and some to “General” (when viewed in Excel immediately after PA exports it). Attempting to set the formatting in Power BI either results (upon trying to refresh the data) in some of the cells becoming “error” or a mix of date formats e.g. 1/12/2024 or 12/1/2024.

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary 1,500 Likes 2500 Comments Name Dropper

    @Shaun Germany
    been a while since your last reply, so not remembering too much, something about date format month/day day/month.

    Power BI doesn't work like excel, so excel “format” of General or “Custom” means nothing to Power BI.

    Can you specify what you are trying to do , what you have done so far, and where you are stuck?

Categories