## Function into EVAL() ?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

### Function into EVAL() ?

Hello to everyone, I'm currently having a problem with my code.

I'm currently using iMacros build 844 on Google Chrome and on Windows 10 in french.

Let me explain you. My goal is to take a part of the URL and to change juste a number into it, adding it 1.

Here is my code :

VERSION BUILD=844 RECORDER=CR
SET !TIMEOUT_PAGE 15
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

SET !VAR1 {{!URLCURRENT}}

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\";
function incremente(expression){
var expression1 = "";
expression1 = expression.match(/\d{1,}/);
expression1 = expression1 + 1;
expression1 = '&page' + expression1 + '&';
return expression1;}
s.replace(/&page=\d{1,}&/, incremente(/&page=\d{1,}&/));")

PROMPT {{!VAR1}}
PROMPT {{!VAR2}}

And this does not work telling me : SyntaxError: wrong format of SET command...

Is it possible to declare a function directly into an EVAL() in iMacros? I've been looking for some answers on the web and it's a bit difficult to find.

If someone could help me, it would be nice! Best regards.
dance4me

Posts: 8
Joined: Mon Sep 25, 2017 7:28 am

### Re: Function into EVAL() ?

Hello,
dance4me wrote:Is it possible to declare a function directly into an EVAL() in iMacros?
Why not?

Code: Select all
`SET !EXTRACT someStuff&page=100&someStuffAgainSET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; function incremente(expression){var expression1 = parseInt((\"\" + expression).match(/\\d{1,}/)) + 1; expression1 = '&page=' + expression1 + '&'; return expression1;} s.replace(/&page=\\d{1,}&/, incremente(s.match(/&page=\\d{1,}&/)));")PROMPT {{!EXTRACT}}PROMPT {{!VAR2}}`
iimfun

Posts: 239
Joined: Tue Jul 19, 2016 6:06 am

### Re: Function into EVAL() ?

Thank you very much for sharing your knowledge!

Question :

May I ask why you use : parseInt((\"\" + expression).match(/\\d{1,}/))

Remark :

You wrote : s.replace(/&page=\\d{1,}&/, incremente(s.match(/&page=\\d{1,}&/)));")
I would think there is no need to \\ in the match parenthesis since s.match is waiting for a regex. Don't you think so?

Thanks again and have a good day
dance4me

Posts: 8
Joined: Mon Sep 25, 2017 7:28 am

### Re: Function into EVAL() ?

dance4me wrote:Don't you think so?
Just feel free to edit the macro as you'd like.
iimfun

Posts: 239
Joined: Tue Jul 19, 2016 6:06 am