BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

@AhmedAl_Attar I'd like to know how to dynamically use the path/folder name in HTML. In the following code, you can see that path name (/Environments/Dev/Jobs/html_job/prompts) is hard coded and it has the folder name called 'DEV'. This folder name is TEST and PROD, when we move this code to test and production environments respectively. I don't wish to manually correct this path when we promote this code to higher enviornments. 

 

What would be the efficient way to handle this?

 

<div class="divTableCell">
              <select name="_division_sel" id="_division_sel" class="jobexec_select" multiple hidden onchange="get_data('pf_ncnm_sel', '_division_sel', '/Environments/Dev/Jobs/html_job/prompts', 'DIVISION', 'SECTION', 'pt_div_map.sas7bdat' )">                
              	<option value="Insurance">Insurance</option>
                <option value="Life">Life</option>
                <option value="NonLife">NonLife</option>                
                <option value="Loan">Loan</option>
              </select>
            </div>
 

 

AhmedAl_Attar
Ammonite | Level 13

@Babloo 

 

To me this looks more like a JavaScript function

get_data(args[*])

design flaw!

  1. Change your JavaScript Function signature/definition and hide away the path to your Job entry.
  2. Add a Parameter definition (P_ENV) to your Viya Job Entry to hold the value of the Environment you are running in (Dev/Test/Prod)
  3. Within your JavaScript Function, get the value of the Environment and concatenate the path dynamically. I would guess SAS will place this parameter somewhere with your HTML Page and allow you to access its value via "$P_ENV$". Similar to how we did here 
    formData.append("_program", "$PROGRAM$");​

Hope this helps

Babloo
Rhodochrosite | Level 12

@AhmedAl_Attar Were you can elaborate the point 3 which is, 'Within your JavaScript Function, get the value of the Environment and concatenate the path dynamically. I would guess SAS will place this parameter somewhere with your HTML Page and allow you to access its value via "$P_ENV$". Similar to how we did here '?

 

I couldn't understand how SAS will pass the parameter value of  "$P_ENV$". to HTML ? How to call this parameter in HTML?

AhmedAl_Attar
Ammonite | Level 13

@Babloo 

Check the SAS supplied Samples Jobs: https://documentation.sas.com/doc/en/sasstudiocdc/5.2/pgmsascdc/jobexecug/n0t91q5lsc2b8qn14fd0cgbmyl...

 

My guessing would be, SAS would place your custom parameter(s) as hidden Input field(s) similar to how it does for some of the default out-of-the-box Parameters

<input type="hidden" name="_program" value="$PROGRAM$"/>
<input type="hidden" name="_action" value="execute"/>
<input type="hidden" name="_output_type" value="ods_html5"/>

So, if you were to use a parameter name as p_env, then you would use this in your JavaScript

var env = document.getElementById("p_env").value; 

 if getElementById does not return the value you want, you may want to look at this link https://codepedia.info/javascript-get-hidden-field-value-by-id-by-name for alternative methods.

 

Hope this helps

Babloo
Rhodochrosite | Level 12

@AhmedAl_Attar In the current JES job there is one prompt called 'Need Old Data' and it's a drop down and it has values 'Yes' and 'No'.  If you select either 'Yes' or 'No' then the prompts Region, Country and Zipcode will display and all these three prompts are combo box which will fetch data from  different SAS datasets.

 

E.g. If 'Need Old Data' is Y then the values for the prompts Region, Country and Zipcode will be fetched from old_data_reqd_reg, old_data_reqd_cntry and old_data_reqd_zipcd

        If 'Need Old Data' is N then the values for the prompts Region, Country and Zipcode will be fetched from old_data_nt_reqd_reg, old_data_nt_reqd_cntry and old_data_nt_reqd_zipcd

 

In a nutshell, data will be fetched from the 3 different datasets out of 6 based on values from the prompt 'Need Old Data'.

 

Now I'm converting to HTML and have written Javascript to get data from SAS for these prompt. Structure of the java script to fetch data from one SAS dataset looks like this and I'm also showing you how I'm using the java script in HTML.

 

function get_data(id, ele, program, parameter_1, field, datasource, parameter_3, parameter_4) {
.....
.....
}

<div class="divTableCell">
<select name="ins_lf" id="ins_lf" class="jobexec_select" multiple onchange="get_data('ins_lf', 'ins_lf', '/Jobs/prompts', 'REGION', 'COUNTRY', 'ins_reg_cntry_zip.sas7bdat' )"> 
</select>
</div>

Now my question is,

 

a) How to tweak this Java script to fetch data based on the selection of the values from the prompt 'Need Old Data' . Is there a way to write other 'onchange' in the same line as shown above or should I consider to create other java script with if clause? If you can provide me one example to accomplish this then it would be helpful. Because there are many other prompts  are like this where I need to use Javascript conditionally.

 

b) Should I create 6 prompts namely -  Region_Old, Country_Old,  Zipcode_Old, Region_No_Old, Country_No_Old,  Zipcode_No_Old and display the old or no_old prompts based on the selection of the prompt 'Need Old Data',

Babloo
Rhodochrosite | Level 12

@AhmedAl_Attar  were you able to help on the below mentioned scenario? 

AhmedAl_Attar
Ammonite | Level 13

Hi @Babloo 

Let me first remind you of what I had told you few posts back!

Posted a month ago (112 views)  |   In reply to Babloo
@Babloo 

As a SAS skilled person working with SAS Viya 3.5, My preference would be
1. Use the Task Prompts
2. Optimize my SAS data sets for querying. 

The Task Prompts are more mature and provides lots of functionality out of the box (Stored Process Prompting Framework). It's shortens the development time.
But if you are a Web Stack Developer (Web, CSS, JS, Ajax) you may find the developing the HTML page more appealing, but you'll still need to interact with SAS skilled person, and someone who is familiar with how SAS Stored Processes used to work, as they are fundamentally provide the origin of the Task prompts.

Just my 2 cents

With that said, let me remind you, I'm not a JavaScript developer either, I'm familiar with it, but don't practice/use it.

 

But I'm familiar with Application Design principles and I can tell you,  you are going about this the wrong way!

You'll be much better off adopting MVC (Model-Viewer-Controller) App design paradigm for this quest of yours. Let me break it down for you

  • Viewer: JavaScript Function that controls which SAS back-end program to call, and which HTML drop-down Single/Multiple select widgets to populate with the returned JSON Response from the SAS Server
  • Model: SAS Program/Macro that knows about which data set(s) needs to used and how it needs to be manipulated/processed
  • Controller:  SAS back-end program that gets called by the Front-End Viewer, and figures out what to do based on the passed parameters to it, which Model to call/execute and generate the required JSON response in the required format

If all of the above is beyond/outside your skills set, then I would highly recommend you ask your management team to hire someone with those skills sets to help with achieving your projects objectives/goals.

 

That's all I can advise/help you with for now.

Good luck

 

 

 

 

 

 

 

 

 

 

 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 66 replies
  • 5359 views
  • 32 likes
  • 5 in conversation