OL Learn

To send a value from the records table to the js file

Hello there
I wrote a script that changed the css file by any value. Simple code;

function changeCSS(cssFile, cssLinkIndex) {

var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);

var newlink = document.createElement("link");
newlink.setAttribute("rel", "stylesheet");
newlink.setAttribute("type", "text/css");
newlink.setAttribute("href", cssFile);

document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);

}
var field;
field=4;
if(field!=4){changeCSS(‘css/default.css’,0)}
else{changeCSS(‘css/sinif4.css’,0)}

but I want you to decide according to the value in the records table.
how can I do it

Change the field=4 statement to something like

field = record.tables.detail[0].fields.myCSSid;

Where detail[0] is the index of the row in the detail table from which you want to pick the myCSSid field.

Obviously, you will want to change the names highlighted above to match your data model.

I want to do this in a separate JavaScript file. I need to call the data in the record “change.js” as in the picture.

?MAGE


You can’t do that in a client-side script: the record is no longer available once the page is displayed in the end-user’s browser.

If you want to make the record available (or parts of it) to the browser, then one of the server-side scripts will have to store the relevant values in an element attribute somewhere in the HTML. You client-side script will then be able to retrieve that value since it is stored directly in the HTML.

So for instance, your server-side script would do something like the following to store the value of the field in an element whose ID is myDIV:

$('#myDIV').attr('data-CSSIndex',record.fields['Class Level']);

And your client side script (in your external JS file) could then do something like

field = document.getElementById('myDIV').getAttribute('data-CSSIndex')

to retrieve the value and store it in a variable.

1 Like

Can you help me figure out how to do it? because the background changes according to the “Class Level” variable. In some backgrounds the design is not sitting right.

conditions kullanarak çözdüm :slight_smile:

According to Google translation, the above comment apparently means you solved the issue by using conditions… right?

1 Like

Hi,
I am newbie. What does it mean ‘server-side script’ ? Is it a script in Scripts Pane in Designer GUI? If ‘yes’ can I use syntax $(’…’). instead of query(’…’). ?

I guess client-side script it’s Resources\JavaScripts*js

Yes, server-side scripts are the ones included in the Scripts Pane. And since they are server-side scripts, you can’t use $(), which is the jQuery syntax for client-side scripts (i.e. scripts that run in the browser).