Smart Buttons
Controls/XML Elements
File Operation <FileOperation>
The control can applies to text files such as .txt or .csv. The control can:
-
Write to a text file.
-
Read from a text file.
-
Append text to an existing file.
Configuring
It is recommended to configure using the File Operation XML Generator.
To configure with the File Operation XML Generator:
-
Open the Smart Buttons Editor to create a script.
-
Click File Operation <FileOperation> to display the File Operation XML Generator.
-
Click the Mode arrow to select the desired action.
-
Read to read from existing file content.
ExampleTo read from a file:
-
Click the Mode arrow to select Read.
-
In File path, enter or browse the path for the file. In this example, the text file lists airlines.
-
Enter the Variable name that will hold the response.
-
Optional. Select Read as collection to read each line separately and create a collection of elements in which each line of the text is a separate element.
-
Create a script to print the result on the screen.
Copy<ButtonConf ButtonName="" Description="" QuickCommand="">
<FileOperation Mode="Read" VarName="ListOfAirlinesFromFile" StringToCollection="True">
<FilePath><![CDATA[C:\OneDRive\OneDrive - Travelport\Desktop\TEST TEST\Airlines-test.txt]]></FilePath>
</FileOperation>
<ShowMessage>[ListOfAirlinesFromFile]</ShowMessage>
</ButtonConf>
The list of airlines is displayed in a message box.
-
-
Write to create a new file and write text to the file, or to overwrite text to an existing file.
InstructionsTo write to a file:
-
Click the Mode arrow to select Write.
-
In File path, enter or browse the path for the file.
-
In Source, enter either static text or a variable.
-
Optional. Select Write as collection if the source input is a collection of items separated by semicolon, and you want each element of the collection written on a separate line.
-
Optional. Select Overwrite to replace the text of an existing file. An overwrite message is not displayed to the agent.
-
Append to modify an existing file by adding the text at the end of the file.
ExampleTo append text:
-
Click the Mode arrow to select Append.
-
In File path, enter or browse the path for the file.
-
In Source, enter either:
-
Static text, such as SAS Scandinavian Airlines, as in this example.
-
A variable such as [Airlines].
-
-
Create a script to read the file, display the content in a message box, append the static text, read the file, then display the appended content in a message.
Copy<ButtonConf ButtonName="" Description="" QuickCommand="">
<FileOperation Mode="Read" VarName="ListOfAirlinesFromFile">
<FilePath><![CDATA[C:\OneDRive\OneDrive - Travelport\Desktop\TEST TEST\Airlines-test.txt]]></FilePath>
</FileOperation>
<ShowMessage>[ListOfAirlinesFromFile]</ShowMessage>
Copy<FileOperation Mode="Append" Source="SAS Scandinavian Airlines">
<FilePath><![CDATA[C:\OneDRive\OneDrive - Travelport\Desktop\TEST TEST\Airlines-test.txt]]></FilePath>
</FileOperation>
<FileOperation Mode="Read" VarName="ListOfAirlinesFromFile">
<FilePath><![CDATA[C:\OneDRive\OneDrive - Travelport\Desktop\TEST TEST\Airlines-test.txt]]></FilePath>
</FileOperation>
<ShowMessage>[ListOfAirlinesFromFile]</ShowMessage>
</ButtonConf> -
-
Exists to modify an existing file by adding the text at the end of the file.
ExampleTo append text:
-
Click the Mode arrow to select Exists.
-
In File path, enter or browse the path for the file.
-
In Variable name, enter the name for the variable.
-
-
-
-
Click SUBMIT.