web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Passing Teams ID throu...
Power Apps
Unanswered

Passing Teams ID through Environment Variable

(0) ShareShare
ReportReport
Posted on by 67

Hi, I'm trying to use environment variables to pass in a Teams group ID and channel ID to post a message in Teams on a button click.  I have the following in my OnSelect function:

MicrosoftTeams.PostMessageToChannelV3(
 LookUp('Environment Variable Values', 'Environment Variable Definition'.'Display Name' = "TeamsGroupID").Value, 
 LookUp('Environment Variable Values', 'Environment Variable Definition'.'Display Name' = "TeamsChannelID").Value,
 {
 content: "<ul>
 <li>Type: " & DataCardValue17.Selected.Value & "</li>"
 & If(Last(submittedDates).Date <> First(submittedDates).Date, "<li>Dates: " & First(submittedDates).Date & " to " & Last(submittedDates).Date, "<li>Date: " & First(submittedDates).Date) & "</li>
 <li>What's Happening: " & DataCardValue6.Text & "</li>
 </ul>",
 contentType: "html"
 },
 {
 subject: "Out of Office"
 }
);

 

This snippet works just fine with I have the IDs hardcoded with quotes where I have the 2 env var lookups, but I get the following error when I try to use the env vars:

MicrosoftTeams.PostMessageToChannelV3 failed: {"error": {code": "BadRequest", "message"; "teamID needs to be a valid GUID.",...

 

Can anyone suggest how/if I can correctly pass in these values?  I've tried with both quotes and no quotes around the ID values in my vars.

 

Thanks in advance.

Categories:
I have the same question (0)
  • sperry1625 Profile Picture
    763 Super User 2024 Season 1 on at

    Have you verified that those lookups are returning what you are expecting?

     

    Have you tried storing the values in variables first?  You can try using a With() clause.  I generally use the schema name for lookups as follows:

     

     

     

    LookUp( 'Environment Variable Values', EnvironmentVariableDefinitionId.schemaname = "me_NameOfVariable" ).Value

     

     

     

     

    The schema name never changes where the name can change.

     

     

    Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

  • birgem11 Profile Picture
    67 on at

    Thanks @sperry1625 ... the Lookup isn't resolving to anything in the OnSelect function, but if I put the same lookup formula in the Text property of a label, it resolves to what I expected.  Same if I try to set vars in the OnSelect before the MS Teams call, or even OnStart, they don't resolve to anything.

  • sperry1625 Profile Picture
    763 Super User 2024 Season 1 on at

    Not sure why that is. That lookup should work in all cases. Can you provide examples of what you are doing?

     

    Regards,

    -S

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • birgem11 Profile Picture
    67 on at

    Sure.

    Here is the Text property of my label where you can see it resolving to the value in my env var:

    birgem11_0-1660664489857.png

     

    And here is the same lookup function in the OnSelect property where the resolved value is blank:

    birgem11_1-1660664783817.png

     

  • sperry1625 Profile Picture
    763 Super User 2024 Season 1 on at

    What you have should work but I have seen stranger things happen. Let's try a test.  Just prior to your calls in the OnSelect let's add the following:

    UpdateContext(
     {
     ctxGroupId: 
     LookUp(
     'Environment Variable Values',
     'Environment Variable Definition'.'Schema Name' = "new_TeamsGroupID"
     ).Value,
     ctxChannelId: 
     LookUp(
     'Environment Variable Values',
     'Environment Variable Definition'.'Schema Name' = "new_TeamsChannelID"
     ).Value,
     }
    );

    Then change your call to:

    MicrosoftTeams.PostMessageToChannelV3(
     ctxGroupId, 
     ctxChannelId,
     {
     content: "<ul>
     <li>Type: " & DataCardValue17.Selected.Value & "</li>"
     & If(Last(submittedDates).Date <> First(submittedDates).Date, "<li>Dates: " & First(submittedDates).Date & " to " & Last(submittedDates).Date, "<li>Date: " & First(submittedDates).Date) & "</li>
     <li>What's Happening: " & DataCardValue6.Text & "</li>
     </ul>",
     contentType: "html"
     },
     {
     subject: "Out of Office"
     }
    );

    See if the context variables contain your values.

     

    Regards,

    -S

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • birgem11 Profile Picture
    67 on at

    looks to have the same issue:

    birgem11_0-1660671172169.png

     

    I tried using label.Text in the parameters of the PostMessageToChannel function since the labels seem to be getting populated correctly, but then I get the error in my original post.

  • sperry1625 Profile Picture
    763 Super User 2024 Season 1 on at

    This will not likely change anything, but change your Lookup to use the following:

     

     

    UpdateContext(
     {
     ctxGroupId: 
     LookUp(
     'Environment Variable Values',
     // Change is here **************
     EnvironmentVariableDefinitionId.schemaname = "new_TeamsGroupID"
     ).Value,
     ctxChannelId: 
     LookUp(
     'Environment Variable Values',
     // Change is here **************
     EnvironmentVariableDefinitionId.schemaname = "new_TeamsChannelID"
     ).Value,
     }
    );

     

     

    Regards,

    -S

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • birgem11 Profile Picture
    67 on at

    Same issue unfortunately:

    birgem11_0-1660673464221.png

     

  • birgem11 Profile Picture
    67 on at

    so I know PostMessageToChannelV3 is deprecated, but I'm using it because I haven't found a good replacement to do what I'm wanting.  Any other suggestions for what I could try?

  • sperry1625 Profile Picture
    763 Super User 2024 Season 1 on at

    Can you show me the definition for the Environment Variables? Where is the value stored, as the Default, or a value?

     

    Regards,

    -S

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,055

#2
Valantis Profile Picture

Valantis 666

#2
11manish Profile Picture

11manish 666

Last 30 days Overall leaderboard