Dears,
I have a problem with how to get the desktop path of the current user.
Groovy Script as below:
String desktop_path = System.properties.'user.home' + "/Desktop"
How to translate this script into Custom Actions script?
Dears,
I have a problem with how to get the desktop path of the current user.
Groovy Script as below:
String desktop_path = System.properties.'user.home' + "/Desktop"
How to translate this script into Custom Actions script?
Hi @ShawnLi.
You can read about Custom Script action in this guide: https://kb.workfusion.com/display/RPAe/Script+as+Custom+Action.
Hi @Lera,
Thanks for your reply. I try to edit the script as below, but there’s an error.
How to modify it?
@CustomScriptAction(
output = ‘desktop_path’
)
def customScript() {
desktop_path = System.properties.‘user.home’ + “/Desktop”
}
Can you please show the error message? Also I forgot to mention that you should use double back slash, when you add “Desktop” to the folder - \\Desktop
.
Thank you. I see in the error the following exception:
Caused by: java.lang.ClassCastException: Cannot cast java.lang.String to com.workfusion.studio.rpa.recorder.api.types.RDataType
that means that you need to convert your result from Java String to specific recorder type, in your case this is RString.
Please pay attention to the last line of my script:
@CustomScriptAction(
output = 'result_str' // return script result and assign to a Recorder variable
)
def customScript() {
def String desktop_path = System.properties.'user.home' + "\\Desktop"
result_str = RString.of(desktop_path)
}
Hi @Lera, It’s very helpful! I’m going to learn how to edit scripts.
Thank you for your time and efforts.
Glad to know that I could help . By the way, do you mind if we add your script to Custom Script Code samples?