BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

Hi SAS Community,

 

I am currently doing R&D on how to make SAS Stored Process to read javascript function.

I have a sample javascript function and i put it in SAS Stored Proc file. However, when i run, the javascript function is not displaying at all. I need SAS Community to further guide me on this.

 

Below is the Stored Proc code that contains javascript:

proc printto log="D:\Data\SBO\CDS\ECMSTP\Test\log\Test.log" new;
run;
%LET path=D:/Data/SBO/CDS/ECMSTP/Test/jsgrid-1.5.3;
%put path is &path;


data _NULL_;
file _webout lrecl=2500;

put "<html>";

put "<head>";

put "<title>jsGrid - Basic Scenario Title</title>";
put "<link rel=""stylesheet"" type=""text/css"" href=""demos.css"" />";
put "<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,600,400' rel='stylesheet' type='text/css'>";

put "<link rel=""stylesheet"" type=""text/css"" href=""../css/jsgrid.css"" />";
put "<link rel=""stylesheet"" type=""text/css"" href=""../css/theme.css"" />";

put "<script src=""&path/external/jquery/jquery-1.8.3.js""></script>";
put "<script src=""db.js""></script>";

put "<script src=""&path/src/jsgrid.core.js""></script>";
put "<script src=""&path/src/jsgrid.load-indicator.js""></script>";
put "<script src=""&path/src/jsgrid.load-strategies.js""></script>";
put "<script src=""&path/src/jsgrid.sort-strategies.js""></script>";
put "<script src=""&path/src/jsgrid.field.js""></script>";
put "<script src=""&path/src/fields/jsgrid.field.text.js""></script>";
put "<script src=""&path/src/fields/jsgrid.field.number.js""></script>";
put "<script src=""&path/src/fields/jsgrid.field.select.js""></script>";
put "<script src=""&path/src/fields/jsgrid.field.checkbox.js""></script>";
put "<script src=""&path/src/fields/jsgrid.field.control.js""></script>";
put "</head>";


put "<body>";
put "<h1>Basic Scenario Header</h1>";
put " <div id=""jsGrid""></div>";

put "<script language=""JavaScript"">

        $(function() {

            $(""#jsGrid"").jsGrid({
                height: ""70%"",
                width: ""100%"",
                filtering: true,
                editing: true,
                inserting: true,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 5,
                deleteConfirm: ""Do you really want to delete the client?"",
                controller: db,
                fields: [
                    { name: ""Name"", type: ""text"", width: 150 },
                    { name: ""Age"", type: ""number"", width: 50 },
                    { name: ""Address"", type: ""text"", width: 200 },
                    { name: ""Country"", type: ""select"", items: db.countries, valueField: ""Id"", textField: ""Name"" },
                    { name: ""Married"", type: ""checkbox"", title: ""Is Married"", sorting: false },
                    { type: ""control"" }
                ]
            });

        });
    </script>";
put "</body>";
put "</html>";
run;

the output screen:

Basic scenario only.PNG

Only the html will be read but not the javascript function.

 

Can anyone guide me on this?

11 REPLIES 11
imdickson
Quartz | Level 8

Hi Kurt. Did you mean how did i show the result page?

It is a stored proc in SAS Enterprise Case Management(ECM) or aka SAS Anti-money laundering(AML) tool.

Appreciate if you can further assist.

Kurt_Bremser
Super User

If you access your STP with a browser, the browser will act on the javascript and display the results, but not the javascript itself. To see the javascript, you need to look at the HTML source code.

In Firefox, right-click in the displayed page and select Show Source Code.

andreas_lds
Jade | Level 19

You have to store the files the directory of the web application. Files used by Stored Process WebApp, e.g, have to be stored in ?:\SAS\Config\LevX\Web\WebAppServer\SASServer1_1\sas_webapps\sas.storedprocess.war (using SAS 9.4). To prevent losing your files when applying a hotfix you should add those files to the installation directory.

JuanS_OCS
Amethyst | Level 16

Hello @andreas_lds,

 

sorry for saying this, but I would rather not subscribe to your advise.

While that can be true on versions of SAS previous to 9.4 (and only if you don't have an Apache server as reverse proxy), exactly because you refer to 9.4, all the static content should be better stored on the SAS Web Server (.../sashome/config/LevX/Web/WebServer/htdocs ), or even in the SAS Content Server in case you really need secured content... although I doubt most of the  javascript codes would require secured access.

 

Your solution is technically OK, "per se", and it was actually used before 9.4, but this other option reduces a lot the maintenance of the static content.

andreas_lds
Jade | Level 19

@JuanS_OCS: Thanks for correcting my outdated information.

imdickson
Quartz | Level 8

Hi Andreas, can you further elaborate things to do in the mentioned path? I can navigate to that folder.

JuanS_OCS
Amethyst | Level 16

Hello @imdickson,

 

I think that the first check is to see the actual code that is being written to the output stream. Could you please create an html file from it and attach it to the thread? Then hopefully we can identify the problem. I would expect that the path of the js scripts are not being written properly.

 

The second option I am considering, is that your browser has got some security settings that is blocking the execution of javascript from certain sources.

imdickson
Quartz | Level 8
Hi Juan, i have attached the code in stored proc .sas file. Are those code that you want?

Secondly, yes the top right corner is showing blocked not secured script from loading. However, clicking "allow" will not change anything in the output page still.
boemskats
Lapis Lazuli | Level 10

Hi,

 

@JuanS_OCS actually answered your question, albeit indirectly.

 

The HTML you are writing with your put statements will actually be resolving to something like 

<script src=""D:\whatever\your\path\was/src/jsgrid.core.js""></script>

This is obviously wrong, as your browser needs to load your library from a web server, not a location on your disk. Imagine it being typed into the address bar.

 

What you need to do is copy your src directory with all the .js files you want to load into your Config\LevX\Web\WebServer\htdocs directory so that they are served up by the web server (assuming SAS 9.4). Then doing something like 

 

put "<script src=""/src/jsgrid.load-indicator.js""></script>"

for each of your includes ill load your library correctly.

 

I don't agree with the design pattern of using STPs and put statements to generate HTML when you've got an actual web server / reverse proxy available with your environment, but that's a different conversation altogether.

 

Nik 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 11 replies
  • 1787 views
  • 7 likes
  • 5 in conversation