CRS Script that writes to a csv file

Answered Question
Feb 12th, 2009
User Badges:

Through other posts I figured out how to write a script in CRS 4.0 that allows callers to enter an account number which gets stored in a CSV file on the server. I am using Get Digit String to collect the account number then writing to the file using the Write Document step. The problem is that I need to keep all account numbers entered in the file. In my current script the number gets over written every time a new caller enters an account number. How do I set this up to retain every account number entered by each caller? Thanks for the help!!

Correct Answer by villarrealed about 8 years 5 months ago

I was recalling it from memory. I tested it on my lab box and the syntax to recast the document to a string variable is (String)myDocumentVariable


You will also need to use the + rather than & to concatenate the variables.

Correct Answer by villarrealed about 8 years 5 months ago

You can do something like this:

1) Use the create document step to pull the existing csv file into a document variable.

2) Use the set step to "cast" that document variable with the csv file into a sctring variable. You do this by using the toString method. myDocumentVar.toString()

3) Append the account number to the string variable using the set step. myStringVar & myAccountNumVar

4) Use the write document step to save the new doc.


Since the file is pulled for each call, you may end up with some missing account numbers when multiple callers call in at the same time.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
bsugamele1 Wed, 02/18/2009 - 13:50
User Badges:

No answers? All I am trying to do here is capture a number entered by callers with a script and input into a file somewhere.


I can get the script to send the number to a csv file, but it gets over written with each new caller. I need it to store a number for each caller. Help please! Thanks.

villarrealed Thu, 02/19/2009 - 07:21
User Badges:
  • Bronze, 100 points or more

You will need to store the information from the csv file in a variable, append the new data to the variable, then write the variable data to the csv file.

bsugamele1 Thu, 02/19/2009 - 08:35
User Badges:

Ok, that makes sense, but I'm not sure how to implement it.


Right now this is how my script reads:


= Set strfilename = "C:\filename.csv"

enteredNum = GetDigitString (Triggering Contact)

- Successful

- set documentvariable = enteredNum

- Write Document (documentvariable to strFilename)



I'm assuming that I would append the variable before the write document step, but I do not see an "append" step. Can you be more specific??


Thanks for you help. By the way we are looknig at Calence to help us with our CCM IPCCx Unity upgrade from 4.0 to 7x. I'm looking forward to getting on the new version!

Correct Answer
villarrealed Thu, 02/19/2009 - 10:59
User Badges:
  • Bronze, 100 points or more

You can do something like this:

1) Use the create document step to pull the existing csv file into a document variable.

2) Use the set step to "cast" that document variable with the csv file into a sctring variable. You do this by using the toString method. myDocumentVar.toString()

3) Append the account number to the string variable using the set step. myStringVar & myAccountNumVar

4) Use the write document step to save the new doc.


Since the file is pulled for each call, you may end up with some missing account numbers when multiple callers call in at the same time.

bsugamele1 Thu, 02/19/2009 - 12:34
User Badges:

Ok, I have the code working except for the append part. myStringVar & myAccountNumVar does not work. The only operator I have found that works with two string variables is + (concatenate).

bsugamele1 Thu, 02/19/2009 - 13:41
User Badges:

Actually I did some further testing and I can now append to the file but I think there is something wrong with my document to string translation. Here is how it looks:


= Set docCashNumList = strCashNumList.toString()


= docCashNumListFinal = strEnteredCashNum + strCashNumList


Write Document (docCashNumListFinal to "C:\CashNumListFinal.csv")


If I remove the right operand when appending the strings and put in a literal string like "1234" the output file will have the entered number and "1234" next to it which is fine. But when I put the strCashNumList variable back in all I get is the entered number.


Thanks again for all your help. I didn't realize I had to become a java programmer to write scripts!

bsugamele1 Thu, 02/19/2009 - 14:17
User Badges:

I've figured out that this does not work: myDocumentVar.toString()


The expression editor will not accept a doc variable in front of .toString(). Any other ideas?? Thanks.

Correct Answer
villarrealed Fri, 02/20/2009 - 16:31
User Badges:
  • Bronze, 100 points or more

I was recalling it from memory. I tested it on my lab box and the syntax to recast the document to a string variable is (String)myDocumentVariable


You will also need to use the + rather than & to concatenate the variables.

Actions

This Discussion