I need help with importing from CSV, outputs double quotes ""

Hi there , I have this code:

{
  "Name": "test",
  "CreationDate": "2020-6-27",
  "Commands": [
    {
      "Command": "store",
      "Target": "1",
      "Value": "!csvReadLineNumber"
    },
    {
      "Command": "csvRead",
      "Target": "test.csv",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var letters = ['Your car is ${!COL1}','Your car is ${!COL2}'];  var string = '';  for(var i = 0; i < 1; i++){string += letters[parseInt(Math.random() * 2)]}; return string;",
      "Value": "TITLE"
    },
    {
      "Command": "type",
      "Target": "id=title",
      "Value": "${TITLE}"
    }
  ]
}

The output variable is: “Your car is “red””

When filled into a form it shows : Your car is “red”

How can I get it to work ??

What is the content of csv ?

It’s a normal csv file as any other :
red,blue,green,black

I want to randomize the value ${TITLE}

Use csvread to fill the form i do not see any utility in your code with javascript

Your work be be done with few command and will be fast and easy.

To randomize create 2 or more lines with text in your csv and change the line of csv to read simple and fast solution.

https://ui.vision/rpa/docs/selenium-ide/csvread

As I said , I want to randomize the value ${TITLE}

{
“Command”: “executeScript_Sandbox”,
“Target”: “var letters = [‘Your preferred color is {!COL1}’,’ Your car is {!COL1}’,’ The water is {!COL1}’,’ Your car is {!COL1}’]; var string = ‘’; for(var i = 0; i < 1; i++){string += letters[parseInt(Math.random() * 4)]}; return string;”,
“Value”: “TITLE”
},

It returns: Your preferred color is “red”
or : Your car is “red”

and it should return the string without double quotes “” like this : Your preferred color is red

Why you randomize in this way ?

What is the sense ?

Put in csv all lines with all string and use it directly.

Change csv from
red,blue,green,black

To
Your preferred color is red, Your preferred color is blue, Your preferred color is green, Your preferred color is black

And randomize csv line to read, is simple and fast.

Another solution is type Your preferred color is and adding COL1 value with random lines

Simple and fast.

Cannot do it your way, my CSV has 40 rows already . I worked 10 years with imacros and it can be done my way , getting part of the string from a CSV file . I spent 1 week on this code and cannot make it work in ui vision .

Working code on imacros :

SET !VAR7 EVAL(“var letters = [‘Appartamentoinpienocentro’,‘Appartamentobilocale’,‘Appartamentoristrutturato’,’]; var string = ‘’; for(var i = 0; i < 1; i++){string += letters[parseInt(Math.random() * 3)]}; string”)

SET TITLE1 {{!VAR7}}in{{!COL2}}
SET TITLE2 {{!VAR7}}a{{!COL3}}
SET TITLE3 {{!COL3}}{{!COL2}}
SET TITLE4 {{!COL2}}{{!COL3}}
SET TITLE5 {{!VAR7}}

SET !VAR1 EVAL(“var letters = [’{{TITLE1}}’,’{{TITLE2}}’,’{{TITLE3}}’,’{{TITLE4}}’,’{{TITLE5}}’]; var string = ‘’; for(var i = 0; i < 1; i++){string += letters[parseInt(Math.random() * 5)]}; string”)

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:form_register ATTR=ID:titolo CONTENT={{!VAR1}}

There are more ways to do your work but the very easy is this

I use imacros from 10 years, and ui vision from 1 year and I can confirm that ui vision RPA can do all automations of imacros and more other automations, sometimes i automate addons and browser internal menu (impossible to do with imacros).

Log

[status]

Playing macro Replace

[info]

Executing: | store | Your car is “red” | MyValue |

[info]

Executing: | echo | ${MyValue} | #shownotification |

[echo]

Your car is “red”

[info]

Executing: | executeScript_Sandbox | var mystring = ${MyValue}; var replaced = mystring.replace(/"/g,‘’); return replaced | MyValue |

[info]

Executing: | echo | ${MyValue} | #shownotification |

[echo]

Your car is red

[info]

Macro completed (Runtime 1.38s)

Macro Code

{
“Name”: “Replace”,
“CreationDate”: “2020-6-28”,
“Commands”: [
{
“Command”: “store”,
“Target”: “Your car is "red"”,
“Value”: “MyValue”
},
{
“Command”: “echo”,
“Target”: “${MyValue}”,
“Value”: “#shownotification
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “var mystring = ${MyValue}; var replaced = mystring.replace(/"/g,‘’); return replaced”,
“Value”: “MyValue”
},
{
“Command”: “echo”,
“Target”: “${MyValue}”,
“Value”: “#shownotification
}
]
}

Image

Well this is why I started using ui vision lately, there is a bigger potential here , as long as my scripts work :slight_smile: . So , now as for your macro … I tried several times adding it even TAB VIEW and also copy paste directly to JSON source view and it gives me errors on the javascript line .

Now I checked the double quotes inside the javascript

and replaced them with normal double quotes and it still gives me an error over the /g

This is not the first time I’m seeing this error while using javascript . I tried removing the double quotes before with different java scripts … What am I doing wrong ?

The forum change ’ character you must fix ’ with correct character

The macro code is tested and working well.

{ "Command": "executeScript_Sandbox", "Target": "var mystring = ${MyValue}; var replaced = mystring.replace(/\"/g,''); return replaced", "Value": "MyValue" },

After you must integrate the code in your macro code

DONE !

Working now like a charm . Thanks a lot …

  • [status]

Playing macro test nou

  • [info]

Executing: | store | Your car is “red” | MyValue |

  • [info]

Executing: | echo | ${MyValue} | #shownotification |

  • [echo]

Your car is “red”

  • [info]

Executing: | executeScript_Sandbox | var mystring = ${MyValue}; var replaced = mystring.replace(/"/g,’’); return replaced | MyValue |

  • [info]

Executing: | echo | ${MyValue} | #shownotification |

  • [echo]

Your car is red

  • [info]

Macro completed (Runtime 0.22s)

Thanks for @newuserkantu for the good workaround. I also added this to our todo list. The “” should not be there.

1 Like

You are constantly saying to the people “You are doing it wrong”, “Your way of doing things is bad”, “My way is better” and I think that’s harassment, my friend. You are not trying to help, you are just trying to prove yourself better in an arrogant way, disencouraging new people.

What you say is not true because I helped so many people in the forum for free, I recommend the easiest way to automate.

I use imacros for 10 years and I am very experienced in automating so I recommend the easiest and fastest way.

I am one of the people I have most helped for free here in the forum using my time so I do not accept your criticism I am sorry.

I think you have to make allowance for language differences. I believe newuserkantu is not a native English speaker? However he is very knowledgeable and helpful and means well.

2 Likes

I’m not english and i use translator (bing or google) to read and write.

It may happen that the words I write are not the best because I use the translator to write and often the translator does not translate the sentences well.

It can happen that the translator chooses a term that is not suitable for discussion or also makes mistakes.

If I was offensive I apologize to all of you was not in my intentions but I read and write using the translator and not always the translator chooses the best words.

For this reason I always ask for details to understand well the problem to be solved and I need the simplest possible explanations to understand the problem and then think about the solution.

Sometimes it can happen that with the translator I do not understand well what you write and therefore I can not solve a problem if I do not understand well the meaning and the translator does not always help me in this.

Technical update: It works this way as it works because the more likely use case is ${!COL1}.length > 0 , so for executeScript, we replace ${VAR} with Json.stringify(VALUE_OF_VAR) .

One easy workaround is to rewrite

var letters = 'Your car is ${!COL1}'; returns letters

with

var letters = 'Your car is ' + ${!COL1}; return letters;

Notice that in the new version ${!COL1} is now outside the “”.

I do not think you will be able to find a reason for malfunction so simply. It can be discovered only in a way of applying different solutions and see if they work. I am from Spain, Check This Out. Your project seems interesting to me and I would like to try to fix it. But I will need full access to it to experiment. Please contact me if you are interested in cooperation.