BookmarkSubscribeRSS Feed

Embedding an HTML Input Form in a JES Job Definition

Started ‎07-15-2019 by
Modified ‎07-14-2019 by
Views 5,215

As I mentioned in my SAS Global Form paper, one of the things I like best about the SAS Viya platform is the ability to develop SAS code within SAS Studio 5.1.  From their favorite web browser, developers can log into SAS Viya, open up a code editor, and start creating code that leverages foundation SAS, CAS actions, and Viya APIs! 

 

But did you know that you can also develop SAS code using the SAS Job Execution Web Application?  Within its framework developers can create jobs that can access any SAS data source or external file and create new tables, files, or other data targets that are supported by SAS. More so, developers can create web applications that can execute SAS code and return results directly to the browser! 

 

A job being executed via the SAS Job Execution Web Application (or JES) can be seen in the image below:

 

SC_09.png

 

Another advantage of creating JES jobs is they leverage most of the same concepts used in SAS Stored Process development.  This is great news because you can use lots of your previous Stored Process source code when creating JES jobs!

 

In this two part article series I'll demonstrate how to develop SAS code within the JES framework.  In this first article I'll show you how to take a stored process sample from support.sas.com and modify it to work as a JES job.  In the second article I'll show you how to modify the SAS code in this job and enable it to connect to the Viya reports service!

 

Let's get started!

 

One of the advantages of developing applications using the SAS Job Execution Web Application is the ability to pass user input to a job using an HTML input form.  While this is very nice, it requires developers to build both a job definition and a job form.  Wouldn't it be great if both the user input form and the job definition could be contained within the same JES job? Take a look at this Stored Process Example from support.sas.com.  The SAS code within the example allows the user to submit a SAS® Stored Process request in an HTML Frame.  After submitting the request, SAS code runs and its output is displayed in a second HTML frame.  This eliminates the need to create an external JSP file with the input form and attach it to the Stored Process.  The user selection, as well as the stored process results are displayed on the same page! 

 

So let's see how we can adjust this sample code to work within the JES Framework: 

 

Start by signing into the SAS Job Execution Web Application using this URL: http://host:port/SASJobExecution

 

SC_01.png

 

From here, you can navigate to the Viya content folder where you would like to place your new job.  In the example below, I'm placing mine in the /Public/JES/ folder. 

 

Click the "New File" icon:

 

SC_02.png

 

Input a name for your new job.  In the example below, I've named mine "JES_Frame_Example".

 

Keep the File Types as "Job definition".

 

Press "OK".

 

SC_03.png

 

Now click the "Edit File" button.  Paste the code from the support.sas.com example.  Then press the "Save" button.

 

SC_04.png

 

Now that our job has been created, we are going to have to make a few adjustments for the code to work within the JES framework.  Make the following edits to the SAS code:

 

At lines 27 and 28 make the following substitutions:

Original Code:

thissrv = "&_URL";
thispgm = urlencode("&_program");

 

Edited Code:

thissrv = "&_URL";
thispgm = "&_program";

 

At lines 64 and 65 make the following substitutions:

Original Code:

thissrv = symget('_url');
thispgm = urlencode(symget('_program'));

 

Edited Code:

thissrv = "&_URL";
thispgm = "&_program";

 

Next, insert a new line at line 61 with the following code:

 

put '<input type="hidden" name=_ODSDEST value="html">';

 

Finally remove the %stpbegin; and %stpend; macro calls on lines 94 and 101 respectively.

 

Congratulations!  You've completed all the needed code edits. 

 

Press the "Save" button followed by the "Close" button:

 

SC_05.png

 

All that's left to do is to add a parameter to the job.  To add a parameter, right click on the job file in the left-hand pane and choose "Properties":

 

SC_06.png

 

At the next window, expand the "Parameters" menu and choose "New Parameter":

 

SC_07.png

 

For the parameter name input "_output_type".

 

For the default value, input "html".

 

Press "Save".

 

SC_08.png

 

Good job!  You've successfully converted the stored process code to work within the SAS Job Execution Web Application!

 

To test your new program, press the "Submit Job" button at the top of the left hand pane.  The job's output will be displayed either within the right-hand pane or in a new tab.  From here you can make a selection on the user input form on the left.  The input will first be passed as a parameter to the job.  The job will then run and it's output will be displayed in frame 2 on the right:

 

SC_09.png

 

And there you have it!  You have a SAS Job Execution that presents the user with both a user input form and the job's results on the same html page.  And the best part is we didn't need to create a job form to hold the HTML code for the job's selection.  Everything is contained within the source code of our job definition!

 

How to make this example work for you

On GitHub, you will find all the code discussed in this article.  All code intended to be saved in a SAS® Job Execution Web Application 2.1 job definition within a Viya 3.4 environment. 

 

 Take Me to GitHub!

 

Next Article

 

In my next post, I'll show you how to add higher level functionality to the job from this article by adding SAS code which makes REST API calls to the Viya reports service!

Comments
We've completed successfully the first job.
Thanks for your post.
I wonder if I can pass the control related parameter from a slider for example to the job execution without prompting the user again for any input.

What a great idea!  I'll research it, and if it's possible...I'll write a post about it!

 

- Mike

We've found a way that looks promising.
It's achieved by combining controls and its parameters, their conversion to calculated items and their usage in objects like list fields.
The list entries get populated by the user chosen inputs and clicking on the list item we run the job execution.
It's possible because the list element can be pointed to a web link and even can pass parameters.
Magic

That does sound promising!

 

Sounds like you're halfway to writing a post about it!  🙂

 

- Mike

Version history
Last update:
‎07-14-2019 04:56 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags