cancel
Showing results for 
Search instead for 
Did you mean: 

global variables

Former Member
0 Kudos

Is there a way to set a global parameter in Java scrip thtat does not require a selectionevent or onload? I would like to place a variable in the <script> </script> that I will be able to pass in multiple applets and browsers on the current irpt.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Yes, there is.

Inside the <script></script> tags, but outside of any functions, just define the variable:


<script type="text/javascript">
// my global variable
var FAVORITE_COLOR = "red";
// functions...
function function1() {
// more code
}

You can now reference the FAVORITE_COLOR variable in any function on the page. Some people CAPITALIZE the global variable so that is easily recognized as a global variable.

Now, keep in mind this variable only exists on the page. It is not global to the application. For that, you would have to throw it in a session property, but then the variable is only accessible to the current session.

Former Member
0 Kudos

I got this far while I was waiting for a response. I am now trying to pass this var into my applets. I thought the {var FAVORIT_COLOR} in the param of the applet would work but it didn't. So I took a different approach and set the param using the javascript when the body loaded. I am seeing some problems with this.

Here is what I have so far and please advise if there is a better way.

<script type="text/javascript">

var Product = 'FW';

function Load()

{

document.AP1.getQueryObject().setParam(1, Product);

document.AP2.getQueryObject().setParam(1, Product);

document.Grid.getQueryObject().setParam(4, Product);

}

</script>

I would much rather do this...

<tr>

<td>Program:</td>

<td>

<applet name="AP1" codebase="/Illuminator/Classes" code="iBrowser" archive="illum8.zip" width="200" height="25" mayscript>

<param name="DisplayTemplate" value="../dspQA_MTR_XRAY_PRGLIST">

<param name="QueryTemplate" value="../qryQA_MTR_XRAY_PRGLIST">

<param name="SelectionEvent" value="P1">

<param name="ShowVerticalGrid" value="false">

<param name="Param.1" value=''>

</applet>

</td>

<tr>

Former Member
0 Kudos

Yes, don't get into the habit of calling a function that interacts with applets using a body onload function. The problem is, that if the body loads faster than the applets (which is usually the case), the javascript in the function will be trying to take action on something that doesn't exist yet.

The better way to do it is to use the CreationEvent of the applet. So that way after the applet is created, it calls the javascript function. And since the javascript is stored in the head part of the html document, you're guaranteed that the javascript will be there when the applet loads.

It is OK to use the body onload event when dealing with form elements and other html object, just not applets. HTML does not have a good way of loading or synchronizing applets consistently.

Former Member
0 Kudos

I think you told me that once before. I just needed a refresher. Is there a way to pass parameters or the global variable into the display and query template? I would like to control globally the location of all of the files or folders from one variable.

Former Member
0 Kudos

I'm not sure what your question means. In your examples, you were passing the global variables into the display / query templates.

Or do you want to change the PATH to the templates in the applet definition? You can do that through session parameters.

...

<param name="QueryTemplate" value="/MyTemplate">

...

Former Member
0 Kudos

I do want to change the path in the applet definition, but I was thinking about the CreationEvent and wondering how I could set the PATH that way.

Former Member
0 Kudos

How would you declare your ?

I just tried this and it is not working.

Former Member
0 Kudos

the dev_location would be a session property tied to the user.

Former Member
0 Kudos

Isn't this how you would set up a session variable?

var dev_location = 'Lighthammer/QA'

I want it to be a global variable or can I not do this?

<param name="QueryTemplate" value="/qryQA_MTR_XRAY_LINELIST">

Do I have everything setup properly?

Former Member
0 Kudos

Anything in the swirly braces "{}" is a session property in irpt pages.

If you use the session properties, you do not need to use javascript and a global variable to set this in the query template. It automatically happens when you load the page.

if this is your query template param:

<param name="QueryTemplate" value="/qryQA_MTR_XRAY_LINELIST">

Then either create a session property called Location and tie to your user or role or append the url to the irpt page with:

http://myserver/mylocation/mypage.irpt?myvar1=somevalue&Location=somelocation

Former Member
0 Kudos

I see what you are saying. Then I do not want to use a session property. I would rather use a global variable. Is this possible?

Former Member
0 Kudos

Well, if I understand what you are trying to do, I would think you WOULD want to use the session property as the user/role will have this defined on every page automatically.

If you do a javascript global variable, you'll need to define this variable on every page, or link a single javascript file to every page.

Former Member
0 Kudos

My over all goal in creating a variable instead of using a session variable is from a maintenance standpoint. It has nothing to do with the user. Only for me. When we create an irpt, display and query they are stored in the same folder structure for easy retrieval. This way we are never confused to where we have our files. What I am seeing is when we create irpts, there is alot of redundant typing or copying and pasting. I would like to create a variable at the top of the screen in the script section that holds our folder location. I would eventually have file names here as well since we use the same structure for all of our files. The only difference would be our prefixes for each file. query we use qry, displays are dsp and so on. I would like our display template and query template to look like this...

<param name='DisplayTemplate' value= & 'dsp' & > <param name='QueryTemplate' value= & 'qry' & >

What I have as an example I know is not close to being proper syntax, but that is my request and I a hoping there is something I can do to accomplish this. I don't want to write this as a session variable because I would have to do all of this in the html address and I usually call the address from the tree menu.

Former Member
0 Kudos

Any thoughts on this?

Former Member
0 Kudos

OK, I think I understand what you are asking and why you are asking it. It's an interesting approach; I haven't seen it done before. Maybe that is a word of caution?

What you could do, if you decide to go further with this approach is create a Session Property at a Role or User level called "Folder". This can be done through Security Services in xMII or in LDAP if you are tied into one.

If you assign a Session Property at the Role or User level as a User or Role Attribute in Security Services, that value and property is available immediately after login. (You would not even have to define it at the top of every page or modify the URL on the navigation menu).

That should take care of the "" part of your example below. The "" part might be a bit too much?

I understand having to copy/paste or retype a lot of code. One thing that I have tried to find a work around for (and gave up) is having to declare applets in each js function. For instance, if you have a basic iGrid on the page called "Orders", but there are 8 JS functions on that page that use the iGrid, each JS function has to use document.Orders.getGridObject() or document.Orders.getQueryObject(). It would be nice if you could define variables once on a page maybe myGrid = document.Orders.getGridObject() and myQuery = document.Orders.getQueryObject() and use the myGrid and myQuery variables in each of the 8 javascript functions.

The problem with this is if you declare the global variables myGrid and myQuery in the script section of the head, they reference applets that might not have loaded on the page yet (causing errors). You could add the script to the bottom of the body section, but... and there were a whole bunch of other things I tried.

Former Member
0 Kudos

One other point to mention. It seems like you might be a little confused between Session and URL properties.

Both work on irpt pages with the "{ }". The difference is in the scope of their existence. Session properties are stored in memory and are available for the duration of the user's session (login to logout). They are created during login if they are defined as user or role attributes in Security Services. You can also create Session properties via the applet's java methods (getPropertyValue() and setPropertyValue()).

URL properties only exist and are only created via URL calls. They can be referenced on an irpt page using the "{ }". However, to create a URL property, you specify them in the URL. (http://www.sap.com/mypage.irpt?myUrlProperty1=somevalue&myUrlProperty2=someothervalue...) The URL properties only exist on the page of the url; in the example above - mypage.irpt.

The purpose of the session and url properties are to persist data across pages and requests. The difference is in the scope of the properties. Sessions exist in the session and for the duration of the session and url properties exist only during the current url.

Hope that helps clear up the difference between the two.

Former Member
0 Kudos

This is exactly what I am trying to do. I am at the point where I have created a basic template that has four ibrowsers, one iGrid and one iSPCChart. I have named each one of these applets a vague but specific name. Once I was satidfied with the basic java layout, I rolled it in production and everything works fine. Then I had to create a nearly identical irpt and I was able to save about 5-10 minutes of cutting and pasting. What is left to my template is the folder and file names. If I can get this, I think I will be able to really cut some coding time.

Former Member
0 Kudos

Try this:

<param name='DisplayTemplate' value='dsp'> <param name='QueryTemplate' value='qry'>

Former Member
0 Kudos

I have tried this and I can not get it to work. Any thoughts?

var Folder = '../FR/'

var File = 'FR_ATD_Production_History'

<param name='DisplayTemplate' value='dsp'> <param name='QueryTemplate' value='qry'>

Former Member
0 Kudos

Yes, couple things. First, any variable in a {} is a session or url property which is different from setting a local javascript variable as "var Folder = '../FR/;"

If you want to do the

<param name='DisplayTemplate' value='dsp'> you must pass the values of "" and "" into the page as either a session or url property. You can not set these on the page in javascript (using local variables) and expect it to work.

If you create a session variable for "Folder" and "File" then you don't need Javascript.

If you create a url variable for "Folder" and "File" then you don't need Javascript.

Also, you should probably avoid using relative paths to the templates (as in your Folder variable). I'm actually surprise that this is working for you.

When you type "var Folder = "../FR/", it creates a javascript variable that only exists inside the open script (<script>) and close script (</script>) tags. The "" variable in your applet parameter will not look in the javascript code to find out what "Folder" is. It will however look in the Session and URL areas.

Former Member
0 Kudos

How do I pass the values of "" and "" into the page as a session property without using the Security services you suiggested a few post ago?

Could I have a hidden html field on the irpt and use the value of it as a variable?

Former Member
0 Kudos

Tell me again why you don't want to create a session variable in Security services for "Folder". If all of your templates really are in the same folder, you set the value in Security services and then the Folder part of your path would just always work.

Former Member
0 Kudos

I guess I don't understand how to set the value in the security services.

Former Member
0 Kudos

In Security Services, check out either the User Attributes or the Role Attributes (on the navigation menu). You can define custom attributes for users and roles.

You probably have at least one role that all users belong to (your company name). If you create a custom role attribute called "Folder" and then in the Role add the Folder attribute to the CompanyName role, you can give Folder a value.

When any user that belongs to the CompanyName role logs into xMII, they automatically get a session property called Folder with the value you specify. You can then use that property in any irpt page by typing "".

Former Member
0 Kudos

You said...

<i>When any user that belongs to the CompanyName role logs into xMII, they automatically get a session property called Folder with the value you specify.</i>

Ok, but how am I assigning the value to the session property?

Former Member
0 Kudos

<i>...and then in the Role add the Folder attribute to the CompanyName role, you can give Folder a value.</i>

Whatever value you define in Security Services for the Folder attribute is what is assigned to the Folder session property at login. It happens automatically.

Former Member
0 Kudos

Can I change the value of Folder in the irpt? Or can it only be changed in the Role Attribute? And what happens if we are using LDAP?

Former Member
0 Kudos

OK

Former Member
0 Kudos

Hi xMII_Training,

First of all a big compliment to Ryan who was really patient,

because at the beginning of xMII_Training’s question it wasn’t really clear what you want to achieve.

Ryan was absolutely right to give you the hint with the session variables.

But have you considered looking into the xMII help after this hint?

Coming to your very good question:

1. In my opinion you should only use .irpt pages working with xMII.

2. You know how to assign a Start page for each User entering xMII I believe?

It’s the First Tab in the Navigation Editor. You can also set a Parameter in the

DynamicHompage.xsl which I can’t recall now.

3. Next you make this Start Page.

4. Put a Dummy Applet on the Start Page: name=dummy

5. On the CreationEvent of the Applet you call a JavaScript function.

6. Use dummy.setPropertyValue(“myFolder”, “however/”) to set a Session variable

at runtime. Now this variable is available on all your .irpt Pages for the whole

xMII Session. => “global available”

7. Use <param name='QueryTemplate' value=”qryCurrentSpeed”> 8. Use var x = appletname.getPropertyValue(“myFolder”) to get the value in JavaScript on every Page 9. Or use a hidden input variable on every page to store the value of

and use getElementById.myHiddenField.value to get the value in JavaScript.

10. If you work with “dynamic Folders” you should also prepare a Transaction

Variable for your Folders to use on each Transaction as input (Hint: Search for

the “AutoBind” Property of the Xacute Connector in the help).

Ok the only Problem is now that you have to take care that no user walks from your Start Page until all Session Variables are assigned.

Session Variables and User and Role Attributes are nearly the same reagrding how they are treated in between

the HTML-Tags. You can alwas get their value using {}.

Hope this helps.

Ciao

Martin

Answers (0)