Joining parts of two variables

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
jhodgson14
Posts: 6
Joined: Tue Apr 16, 2019 12:57 pm

Joining parts of two variables

Post by jhodgson14 » Wed Apr 17, 2019 2:03 pm

Hi There,

Quite an iMacros noob here, so please bear with. I have created an iMacro to do a dumb part of an order system we use that creates a customer then uploads some files. The name of the folder that each customer has is the first four letters of their surname and then the first letter if their first name. This is currently set as a variable via a prompt that appears(See below). How could I set the third variable in the code as the information is already there by that point?

Code: Select all

PROMPT "Please enter First Name" !VAR1
PROMPT "Please enter Last Name" !VAR2
PROMPT "Enter First four letters of LAST NAME and the First Inital, e.g BinnJ = Jeanette Binns" !VAR3
Example of the code that does the upload.

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[0] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}01L.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[1] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}02L.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[2] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}02R.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[3] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}01R.txt
Thanks in advance!
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Joining parts of two variables

Post by chivracq » Wed Apr 17, 2019 2:43 pm

jhodgson14 wrote:
Wed Apr 17, 2019 2:03 pm
Hi There,

Quite an iMacros noob here, so please bear with. I have created an iMacro to do a dumb part of an order system we use that creates a customer then uploads some files. The name of the folder that each customer has is the first four letters of their surname and then the first letter if their first name. This is currently set as a variable via a prompt that appears(See below). How could I set the third variable in the code as the information is already there by that point?

Code: Select all

PROMPT "Please enter First Name" !VAR1
PROMPT "Please enter Last Name" !VAR2
PROMPT "Enter First four letters of LAST NAME and the First Inital, e.g BinnJ = Jeanette Binns" !VAR3
Example of the code that does the upload.

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[0] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}01L.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[1] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}02L.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[2] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}02R.txt
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:upload ATTR=ID:files[3] CONTENT=C:\MOVIES\{{!VAR2}}{{!VAR1}}\{{!VAR3}}01R.txt
Thanks in advance!
CIM...! :mrgreen: (Read my Sig...)

But yep, your '!VAR3' can be "computed" based on the first 2 Vars using 'EVAL()' with some JS String Manipulation... Several Solutions, and it's not very complicated... 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
jhodgson14
Posts: 6
Joined: Tue Apr 16, 2019 12:57 pm

Re: Joining parts of two variables

Post by jhodgson14 » Wed Apr 17, 2019 4:59 pm

Hi,

Sorry;
VERSION BUILD=1005 RECORDER=CR
Chrome 75 (Dev Channel, due to 73/74 blocking file uploads)
Windows 10

Thanks J
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Joining parts of two variables

Post by chivracq » Wed Apr 17, 2019 5:24 pm

jhodgson14 wrote:
Wed Apr 17, 2019 4:59 pm
Hi,

Sorry;
VERSION BUILD=1005 RECORDER=CR
Chrome 75 (Dev Channel, due to 73/74 blocking file uploads)
Windows 10

Thanks J
OK, hum, and "very good" indeed about "CR75 (Dev Channel, due to 73/74 blocking file uploads)"...

Missing bit of Info about your FCI: 'Free' or 'PE' Version...?
(As I'm not sure if 'File Upload' is supported in the 'Free' Version...)

And any "Progress" using 'EVAL()' to (try to) find a/one Solution...? :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
jhodgson14
Posts: 6
Joined: Tue Apr 16, 2019 12:57 pm

Re: Joining parts of two variables

Post by jhodgson14 » Thu Apr 18, 2019 12:14 pm

Hi,

Free version (It does support file uploading).

Started to look at EVAL and Javascript but haven't got too far yet, any help would be great!

Thanks J
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Joining parts of two variables

Post by chivracq » Thu Apr 18, 2019 2:15 pm

jhodgson14 wrote:
Thu Apr 18, 2019 12:14 pm
Hi,

Free version (It does support file uploading).

Started to look at EVAL and Javascript but haven't got too far yet, any help would be great!

Thanks J
OK for 'Free', I'll try to remember that 'File Upload' is supported in the v10.0.x 'Free' Version for CR, I would have thought it needs the FIO-Module for File-Access, but that's apparently not the case, you're "lucky"...

OK, then well, for 'EVAL()' and JS, it's not complicated, even for sbd who's never used JS before, and you'll find 100's of Examples on our Forum (+ even more on SOF (Stackoverflow Forum)... The Site I use myself for JS Methods is this one...

But OK, to get you "started", here are already the first 4 Chars of the 'Last Name':

Code: Select all

SET !VAR1 "Jeanette"
SET !VAR2 "Binns"
SET !VAR3 EVAL("var fn='{{!VAR1}}', ln='{{!VAR2}}'; var x,y,z; x=ln.substr(0,4); z=x; z;")
PROMPT First_Name:<SP>_{{!VAR1}}_<BR>Last_Name:<SP>_{{!VAR2}}_<BR><BR>VAR3:<SP>_{{!VAR3}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)

The Syntax I use is pretty easy to adapt and to add extra Functionality to, to "slowly" build your Expression towards the "final" Result you will want, by using the "x,y,z" Temp Vars (and you can add some more if you need), and to debug, by simply changing the final "z" into any other Temp Var you want to check...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
jhodgson14
Posts: 6
Joined: Tue Apr 16, 2019 12:57 pm

Re: Joining parts of two variables

Post by jhodgson14 » Thu Apr 18, 2019 2:39 pm

Brilliant thanks for this!

To be honest I was replying to say I'd worked it out! I wanted to ask how to get it on one line but now I see in your reply!

Code: Select all

PROMPT "Please enter First Name" !VAR1
PROMPT "Please enter Last Name" !VAR2
SET !VAR1 EVAL ("var f = \"{{!VAR1}}\"; f.substring(0,1);")
SET !VAR2 EVAL ("var l = \"{{!VAR2}}\"; l.substring(0,4);")
SET !VAR3 "{{!VAR2}}{{!VAR1}}"
Thanks very much for the help chivracq!!
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Joining parts of two variables

Post by chivracq » Thu Apr 18, 2019 3:24 pm

jhodgson14 wrote:
Thu Apr 18, 2019 2:39 pm
Brilliant thanks for this!

To be honest I was replying to say I'd worked it out! I wanted to ask how to get it on one line but now I see in your reply!

Code: Select all

PROMPT "Please enter First Name" !VAR1
PROMPT "Please enter Last Name" !VAR2
SET !VAR1 EVAL ("var f = \"{{!VAR1}}\"; f.substring(0,1);")
SET !VAR2 EVAL ("var l = \"{{!VAR2}}\"; l.substring(0,4);")
SET !VAR3 "{{!VAR2}}{{!VAR1}}"
Thanks very much for the help chivracq!!
Ah OK, very good...!, you've discovered the 'substring()' Method, and found a Solution by yourself, even better...!! :D

If I adapt my first Script to include the whole Functionality, that would give:

Code: Select all

SET !VAR1 "Jeanette"
SET !VAR2 "Binns"
SET !VAR3 EVAL("var fn='{{!VAR1}}', ln='{{!VAR2}}'; var x,y,z; x=ln.substr(0,4); y=fn.substr(0,1); z=x+y; z;")
PROMPT First_Name:<SP>_{{!VAR1}}_<BR>Last_Name:<SP>_{{!VAR2}}_<BR><BR>VAR3:<SP>_{{!VAR3}}_

It would also be possible to add some extra Formatting to that String, by example by "forcing" the Upper and Lower Cases, even if the User will type "jeanette" or "JEANETTE" or even "JEanette", same with "binns"/"BINNS"/etc..., => with stg like:

Code: Select all

SET !VAR1 "jeanette"
SET !VAR2 "BINNS"
'SET !VAR3 EVAL("var fn='{{!VAR1}}', ln='{{!VAR2}}'; var x,y,z; x=ln.substr(0,4); y=fn.substr(0,1); z=x+y; z;")
SET !VAR3 EVAL("var fn='{{!VAR1}}', ln='{{!VAR2}}'; var t,u,v,w,x,y,z; t=ln.substr(0,1); u=ln.substr(1,3); v=fn.substr(0,1); w=t.toUpperCase(); x=u.toLowerCase(); y=v.toUpperCase(); z=w+x+y; z;")
PROMPT First_Name:<SP>_{{!VAR1}}_<BR>Last_Name:<SP>_{{!VAR2}}_<BR><BR>VAR3:<SP>_{{!VAR3}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)

And you can add some more Functionality if you want..., like for example for Last Names containing a Space (like "von X", "van der X", "de la X" in German/Dutch/French), etc... 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply