1

SOLVED: The error cause was the way I was declaring output var, please see the code

I am trying to create a regex to get the URL from a VSTS attachment in order to sync it with Jira. I tried to create a Run Javascript block with the following input:

Input Data

comment: 
creationDate: 2017-10-11T11:31:19.293Z
lastModifiedDate: 2017-08-29T12:32:51.393Z
location: https://project.visualstudio.com/_apis/wit/attachments/ca6206de-0fab-451a-b0bc-89e70221dfcb
name: Capture.PNG
resourceId: 2255679

What I want to retrieve is the "location", so I thought that this would make the trick:

var regEx = new RegExp('location: (.*)', 'g'); // As mentioned in the comments, the 'g' part is not needed
var path = regEx.exec(inputData);
// output = path[1]; This was failing miserably
var output = [{'path': path[1], 'hello': 'world'}] //This works just fine, I guess the hello world part is not really needed :)

But I always get an error:

TypeError: Cannot read property '0' of null

I have tried to create a simple javascript test to run the same and it works just fine. Can you please help me?

cyuste
  • 71
  • 4
  • @WiktorStribiżew, thanks for your feedback, however I do not think that the problem is related with javascript itself. As I said I have tested the code using http://www.webtoolkitonline.com/javascript-tester.html and it works, with our without the 'g' modifier (I also tested it in zapier both ways but I get the same error) The issue here is that when I copy the exact same code that is working in a regular javascript executor fails using zapier – cyuste Oct 11 '17 at 13:45
  • [Look here](https://jsfiddle.net/vLyfm6og/). If you have an issue with some code, post that code. – Wiktor Stribiżew Oct 11 '17 at 13:49
  • Hello @WiktorStribiżew, I finally found the issue. I will edit my initial question but please remove the duplicated flag as the problem is completely different and might help to others. Thank you for your help! – cyuste Oct 11 '17 at 18:57
  • Great, please post the solution. – Wiktor Stribiżew Oct 11 '17 at 19:21

0 Answers0