Error in Javascript Code ('is not a function'.)

Kelly, Mike@DWR 21 Reputation points
2022-03-23T20:09:42.53+00:00

This regex extracts an email address from a chat message in a teams channel.

JavaScript-------------------------------->
var reg = /([a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9_-]+)/g;
var email = workflowContext.trigger.outputs.body.body;
return email.match(reg);
<-------------------------------------------

Error--------------------------------------->
InlineCodeScriptRuntimeFailure. The inline code action 'JavaScriptCode' execution failed, with error 'email.match is not a function'.
<--------------------------------------------

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,899 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,581 Reputation points
    2022-03-24T10:28:31.53+00:00

    @Kelly, Mike@DWR Thanks for reaching out. As per the response from team trigger the body will contain the JSON object as below. So you need to do a match on the content (string content) and not the JSON body object. You need to add the .content at the end of your 2nd statement in javascript as below. You can always check the output of the trigger from the run history to know what is output JSON object the trigger is returning.

    "body": {  
        "contentType": "text",  
        "content": "<<your actual text content>>"  
      }  
    
    var reg = /([a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9_-]+)/g;  
    var email = workflowContext.trigger.outputs.body.body.content;  
    return email.match(reg);  
    

    Feel free to get back to me if you need any assistance.

    0 comments No comments

0 additional answers

Sort by: Most helpful