BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mtejada
Fluorite | Level 6

Hello, 

 

I have just started using SAS Studio to create custom tasks and have a simple example where I display a folder dialog.

I am trying to change the default folder that is being displayed by input type sasserverpath. How can I change it so it points to a different folder?

 

 

<?xml version="1.0" encoding="UTF-8"?>
<Task schemaVersion="5.3" runNLS="never">
<Registration>
<Name>Custom Task - TEST</Name>
<Description>TEST task</Description>
<GUID>726B2B12-4542-4200-96F4-960C645D767F</GUID>
<Procedures>Data Step</Procedures>
<Version>3.71</Version>
<Links>
<Link href="http://documentation.sas.com/?cdcId=webeditorcdc&amp;cdcVersion=3.6&amp;docsetId=webeditorug&amp;docsetTarget=titlepage.htm&amp;locale=en">SAS Studio User Guide</Link>
</Links>
<Category>DATA</Category>
</Registration>

<Metadata>

<DataSources>
</DataSources>

<Options>
<Option name="FolderPrompt" inputType="sasserverpath" defaultName="NEW_FOLDER" required="false" pathType="folder" promptMessage="Set current working folder">Select a folder: </Option>
<Option name="optionstab" inputType="string">OPTIONS</Option>
<Option name="optionsgrp" inputType="string">EXTRACT SOURCE DETAILS</Option>
</Options>

</Metadata>

<UI>
<Container option="optionstab">
<Group open="true" option="optionsgrp"> 
<OptionItem option="FolderPrompt"/> 
</Group>
</Container>
</UI>

<CodeTemplate>
<![CDATA[

${FolderPrompt.path}

]]>
</CodeTemplate>
</Task>



Capture.JPG

 

 

Second question, is there a way to list all the available methods and properties of the VTL variables used in the custom task?

 

Any inputs greatly appreciated.

 

Thanks,

Mario Tejada

1 ACCEPTED SOLUTION

Accepted Solutions
BrianGaines
SAS Employee

Mario,

 

I’m glad to help, and I’m really glad to hear that you like SAS Studio so far and you are learning how to write custom tasks!

 

Thanks for clarifying your first question. I talked to the developer who created the sasserverpath control. He confirmed that, currently, it is not possible to change the entire default file path, but a request will be made for this feature to be added in a future release. So for now, I believe your workaround is the best way to handle it.

 

Also, I have yet to find an ideal answer to your second question, unfortunately, as the use of java reflection methods such as .getMethods() or .getDeclaredMethods() is not available in the task framework.  One thing I have found to be useful is the .getClass() method, as that will at least tell you the java class for the VTL variable.  Once the java class is determined, you can then reference the java documentation for that class.  

 

This is sort of a trivial example, but in your example task, suppose you did not know that "optionstab" is a string.  In the velocity code, you could include $optionstab.getClass() which would then display as "java.lang.String" in the code window.  From there, you could reference the java documentation for the string class to see which methods are generally available.  The documentation lists methods such as length() and toLowerCase(), so you could use $optionstab.length() or $optionstab.toLowerCase() to return "7" or "options" in the code window.  Again, this is not ideal but for me this has been sufficient.  

 

If there is a specific use case you have in mind, or if you have any other questions about task writing, please post back.  

 

View solution in original post

7 REPLIES 7
mtejada
Fluorite | Level 6

I found a workaround to change the default folder but the task file has to be saved as a *.ctk file. Here are the steps I took:

1. Run the *.ctm file.

2. Change the currently selected folder in the folder dialog to the desired folder.

3. Click SaveAs and save the file as a *.ctk file.

 

This preserves folder path in the task. So the next time I open the task, the "default" folder path displayed is the one that I set when I created the task. This doesn't answer my original question but can be a good workaround.

 

According to the SAS Studio 3.71 Developer's Guide: 

"sasserverpath
The sasserverpath control enables the user to choose a file or folder location on the SAS server. The default folder location is the user’s SAS Home directory."

It doesn't say anywhere that the default folder location can be set to another folder for the *.ctm file.

 

 

BrianGaines
SAS Employee

Mario,

 

Is it that you want to use the default file path but you want control over the name of the folder (such as C:\Users\tejada-mario\NEW_FOLDER), or do you want to change the entire file path (such as C:\differentPath\NEW_FOLDER)?

 

The former is possible by changing the pathType attribute to "project".  That is, if you instead use

 

<Option name="FolderPrompt" inputType="sasserverpath" defaultName="NEW_FOLDER" required="false" pathType="project" promptMessage="Set current working folder">Select a folder: </Option>

then you will see 

folderPath.png

 

To my knowledge it is not possible to change the actual default file path (besides your workaround), but I will check in with other task writers and members of the SAS Studio team that supports the custom task model to confirm.  

 

mtejada
Fluorite | Level 6
Hi Brian,

Thanks for responding to my question. I would like to do the latter - which is:

"to change the entire file path (such as C:\differentPath\NEW_FOLDER)"

I have tried the former approach but I'm not yet totally convinced that it would be the right approach for the task that I am setting up. To paraphrase, I would like the path to default to a specific folder other than the SAS HOME directory.

Thanks for also checking with the other members of the SAS Studio team.

I am a fan of SAS Studio even if I've only used it for a month or two. I am transitioning from Base SAS Enhanced Editor.

Mario
BrianGaines
SAS Employee

Mario,

 

I’m glad to help, and I’m really glad to hear that you like SAS Studio so far and you are learning how to write custom tasks!

 

Thanks for clarifying your first question. I talked to the developer who created the sasserverpath control. He confirmed that, currently, it is not possible to change the entire default file path, but a request will be made for this feature to be added in a future release. So for now, I believe your workaround is the best way to handle it.

 

Also, I have yet to find an ideal answer to your second question, unfortunately, as the use of java reflection methods such as .getMethods() or .getDeclaredMethods() is not available in the task framework.  One thing I have found to be useful is the .getClass() method, as that will at least tell you the java class for the VTL variable.  Once the java class is determined, you can then reference the java documentation for that class.  

 

This is sort of a trivial example, but in your example task, suppose you did not know that "optionstab" is a string.  In the velocity code, you could include $optionstab.getClass() which would then display as "java.lang.String" in the code window.  From there, you could reference the java documentation for the string class to see which methods are generally available.  The documentation lists methods such as length() and toLowerCase(), so you could use $optionstab.length() or $optionstab.toLowerCase() to return "7" or "options" in the code window.  Again, this is not ideal but for me this has been sufficient.  

 

If there is a specific use case you have in mind, or if you have any other questions about task writing, please post back.  

 

mtejada
Fluorite | Level 6

Hi Brian,

 

Thank you for the quick response. I do enjoy working in SAS Studio. I have to admit that I was hesitant to make the switch at first - but the more that I worked in the SAS Studio environment, the more that I see the many benefits that it offers. I have since been trying to gradually convince some of my coworkers to try it out Smiley Happy (particularly those that are hard core base SAS users).

 

Your example answers my second question. I think it is sufficient to know the java class for a particular VTL variable and then reference the java documentation (my java is a little rusty but definitely worth trying to review). It helps to know what methods/properties are available and then develop from there.

 

I can't remember a specific use case right now but will post back once I have one. Thanks again!

 

 

 

mtejada
Fluorite | Level 6

Hi Brian,
Would it be possible to grab the string from one control and concatenate that with the string from another control?


Suppose I have two controls:
Control 1 named $sqlserver contains the string MYSQLserver representing the full sql server instance
Control 2 named $port that contains the port number.

 

Can I concatenate those two so I could can construct the SQL server instance and port number?

$sqlserver.concat(",$port")

 

** leveraging the concat method https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#concat(java.lang.String)

Thanks!

BrianGaines
SAS Employee

Mario,

 

Yes, that should be possible.  Did it not work when you tried it?  

 

In addition to using the concat method, velocity also offers some flexibility when concatenating strings; see the documentation: http://velocity.apache.org/engine/1.7/user-guide.html#string-concatenation

 

So here are at least 3 ways in which it could be done:

 

/* Using concat method */
$sqlserver.concat(",$port")

/* Manually concatenate */
$sqlserver,$port

/* Create new concatenated variable */
#set($fullAddress = "$sqlserver,$port")
$fullAddress

which all render:

serverPort.png

 

Does that accomplish what you are trying to do?

 

-Brian

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1485 views
  • 3 likes
  • 2 in conversation