BookmarkSubscribeRSS Feed
Rian0126
Obsidian | Level 7

Hi,

 

I have a SAS Job with HTML form code which is used in iframe of SAS Visual Investigator's (SVI) page. Without the HTML form code, the SAS Job code correctly fetch the parameter values such as customer_id and first_name of the current entity's SVI page. But when I added the HTML form code, the HTML form code cannot fetch the parameter values; thus, it cannot pass the value to SAS Job code.

 

See attached SAS Job code and HTML form code.

This is the URL I used in iframe of SAS Job page: 

/SASJobExecution/?_program=%2FUsers%2Fviadmin%2FHTML%20JOB%20Test%2FTest&customer_id={%1}&first_name={%2}&last_name={%3}

with parameter values

{%1} = customer_id
{%2} = first_name
{%3} = last_name

SVIpage_withiframe.JPGSVI-iframe.JPGSASJob.JPG

 

Below is the html form code I used:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Run SAS Job</title>
<style>
body {
margin: 0;
padding: 8px;
font-family: "Segoe UI", Arial, sans-serif;
font-size: 14px;
background-color: white;
}

.form-wrapper {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
}

select, button {
font-family: "Segoe UI", Arial, sans-serif;
font-size: 14px;
padding: 4px 6px;
border: 1px solid #999;
border-radius: 2px;
background-color: white;
color: #0078B8;
}

button:hover {
background-color: #f0f0f0;
cursor: pointer;
}

iframe {
width: 100%;
height: 300px;
background: white;
border: 1px solid #999;
}
</style>
</head>
<body>

<form id="dataForm" method="get" action="/SASJobExecution/" target="resultsFrame">
<!-- SAS Job Path -->
<input type="hidden" name="_program" value="$PROGRAM$">
<input type="hidden" name="_action" value="execute">

<!-- Hidden Inputs -->
<input type="hidden" name="CUSTOMER_ID" value="{%1}">
<input type="hidden" name="FIRST_NAME" value="{%2}">
<input type="hidden" name="LAST_NAME" value="{%3}">

<div class="form-wrapper">
<select name="data_type" id="data_type" required>
<option value="" disabled selected>Select</option>
<option value="Customer ID Report">Customer ID Report</option>
<option value="Name Report">Name Report</option>
</select>

<button type="submit" onclick="handleSubmit(event)">Request Report</button>
</div>
</form>

<!-- Output iframe below -->
<iframe name="resultsFrame" id="resultsFrame" src="about:blank"></iframe>

<script>
function handleSubmit(event) {
event.preventDefault(); // Prevent default form submission

const iframe = document.getElementById('resultsFrame');
const form = document.getElementById('dataForm');

// Show "Running..." message inside iframe
const runningHTML = `
<html>
<head>
<style>
body {
font-family: "Segoe UI", Arial, sans-serif;
font-size: 14px;
padding: 10px;
color: orange;
}
</style>
</head>
<body>
Job Running... <span style="font-weight: normal">Started at: ${new Date().toLocaleString()}</span>
</body>
</html>
`;

const blob = new Blob([runningHTML], { type: 'text/html' });
iframe.src=URL.createObjectURL(blob);

// Submit form after short delay to allow iframe update
setTimeout(() => {
form.submit();
}, 150);
}
</script>
</body>
</html>




I hope someone can help me on solving the correct code to use in HTML form code. Thanks.

- Rian

7 REPLIES 7
Rian0126
Obsidian | Level 7

Hi @DeMer 

 

Sorry, I think I'm a bit confused on the exact process on how to do it. Do you mean I change the URL of the iframe by changing the parameters? So instead of the original I used in HTML form code:

<!-- Hidden Inputs -->
<input type="hidden" name="CUSTOMER_ID" value="{%1}">
<input type="hidden" name="FIRST_NAME" value="{%2}">
<input type="hidden" name="LAST_NAME" value="{%3}">

 


it will become:
<!-- Hidden Inputs -->
<input type="hidden" name="CUSTOMER_ID" value="$CUSTOMER_ID$" required>
<input type="hidden" name="FIRST_NAME" value="$FIRST_NAME$" required>
<input type="hidden" name="LAST_NAME" value="$LAST_NAME$" required>

Is my understanding correct?

 

Thank you.

 

Regards,

Adrian

DeMer
Obsidian | Level 7

I would guess you would change the form to

 

<input type="hidden" name="customer_id" value="$customer_id$" required>

 

based on the note in the doc:

       Note: Use lowercase letters in the $param$ string.

Rian0126
Obsidian | Level 7

Stll not working, still canot fetch the parameter values.

Rian0126
Obsidian | Level 7

It just shows:

 

NOTE: customer_id="$customer_id$

DeMer
Obsidian | Level 7

Don't know about SVI.   Normal job forms can be retrieved with a URL of the form

         /SASJobExecution/?_program=xxx&_action=form&customer_id=zzzz

that will do the parameter substitution.

arthurdpereira
Obsidian | Level 7

I apologize for bringing up this topic again, but I managed to transfer parameters as follows:

 

1. Create a Job Execution (Code) for the parameter:

 

Don’t use the form; use the code section and pass the parameter received from SAS Investigator via sessionStorage to an HTML page generated by the SAS code itself. Like this:

 

%global id;

/* %let id = 123456; */

filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.html';

data _null_;
	file _webout encoding='utf-8';

	put '<!DOCTYPE html>';
	put '<html lang="en">';
	put '<head>';
	put '  <meta charset="UTF-8">';
	put '  <title>Redirecting...</title>';
	put '</head>';
	put '<body>';
	put '  <h2>Processing, please wait a moment...</h2>';
	put '  <script>';
	put "    // Save the parameter in sessionStorage"; 
	put "    sessionStorage.setItem('id', '" "&id." "');";
	put "    // Redirect to the desired page";
	put "    window.location.href = '/SASJobExecution/?_program=location_sas_job_html';";
	put '  </script>';
	put '</body>';
	put '</html>';
run;

 

In this part, replace /SASJobExecution/?_program=location_sas_job_html with the location of the next Job Execution in the list, and in the parameter list, add this one as well, in addition to _action:

 

Name: _output_type

Field type: Character

Default value: html5

 

2. Create a Job Execution (HTML Form) that will receive the parameter via sessionStorage:

 

 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Page on SAS VI</title>
		<style>
			body { 
				font-family: system-ui, Arial, sans-serif; 
				background: #f7fafc;
				padding: 40px;
			}
			.box {
				background: #fff;
				padding: 24px 40px;
				border-radius: 10px;
				box-shadow: 0 4px 16px #0001;
				max-width: 420px;
				margin: 40px auto;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<h2>Welcome!</h2>
			<p>The collected id is: <span id="id"></span></p>
		</div>
	
		<script>
			const id = sessionStorage.getItem('id');
			document.getElementById('id').textContent = id ?? '(not found)';
		</script>
	</body>
</html>

I'll assume here that you named the first job parameter and the second one html. Place the submit job for parameter in SAS Investigator and add the parameter you want. In the example above, it would look like this:

 

/SASJobExecution/?_program=...parameter&id={%1}

 

That's it! When you run the SVI page, it will send the request to parameter and then immediately open the HTML.

 

I included only this parameter so you can see how it works, but it works for other SVI parameters as well, like {%2}, {%3}, and so on.

I hope this answer is helpful. If you have any questions, just reach out.

 

SAS Job Execution Developer
I love sharing knowledge and helping the community.

Follow me:
GitHub | LinkedIn

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

Discussion stats
  • 7 replies
  • 1384 views
  • 0 likes
  • 3 in conversation