Your SAS programs, embedded in web apps and elsewhere

SAS Stored Process will not read javascript

Reply
Contributor
Posts: 70

SAS Stored Process will not read javascript

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?

Super User
Posts: 6,936

Re: SAS Stored Process will not read javascript

How did you display the page source code in the browser?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 70

Re: SAS Stored Process will not read javascript

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.

Super User
Posts: 6,936

Re: SAS Stored Process will not read javascript

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 259

Re: SAS Stored Process will not read javascript

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.

Trusted Advisor
Posts: 1,141

Re: SAS Stored Process will not read javascript

[ Edited ]

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.

Super Contributor
Posts: 259

Re: SAS Stored Process will not read javascript

@JuanS_OCS: Thanks for correcting my outdated information.

Contributor
Posts: 70

Re: SAS Stored Process will not read javascript

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

Trusted Advisor
Posts: 1,141

Re: SAS Stored Process will not read javascript

[ Edited ]

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.

Contributor
Posts: 70

Re: SAS Stored Process will not read javascript

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.
Super User
Posts: 6,936

Re: SAS Stored Process will not read javascript

[ Edited ]

What @JuanS_OCS meant was that you should write the HTML to a disk file instead of _webout. Then we can inspect the file for its contents.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 91

Re: SAS Stored Process will not read javascript

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 

Ask a Question
Discussion stats
  • 11 replies
  • 216 views
  • 7 likes
  • 5 in conversation