# Need a quick help on this (JS)

**URL:** <https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632>\
**Category:** General\
**Created:** [July 25, 2017, 6:19am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632 "2017-07-25T06:19:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 6:19am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/1 "2017-07-25T06:19:08Z")

</div>

I mapped the Parameter Observable to get a value but the variable used in storing the value didn’t work in the same JS file. Like this

```
      var number = this.Parameter.map(function(param){return param.user_number;})

```

and I tried using variable ` number ` in a function in the same JS file like this ;

```
      function show(){
          var sql = db.query('select * from result where matric_no = ?', number);
          debug_log(JSON.stringify(sql));
          debug_log(matric_no)
      }

```

but I keep getting [] and **Fuse.Scripting.V8.Object**

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 25, 2017, 7:13am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/2 "2017-07-25T07:13:30Z")

</div>

If you’re calling the `show()` function before the derived `number` Observable is populated, you might not be getting any value there. It’s populated asynchronously.

As for the `Fuse.Scripting.V8.Object`, you can do this: `console.log(JSON.stringify(matric_no))` to see what’s inside complex structures.

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 7:27am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/3 "2017-07-25T07:27:16Z")

</div>

Here is what’s inside

```
  {"_subscribers":[null],"_isLeaf":false,"_values":["2014235020035"]}

```

How do I access that number there in?

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 25, 2017, 7:34am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/4 "2017-07-25T07:34:40Z")

</div>

Since you’re asking about an Observable, why don’t you first go and give [Observable docs](https://www.fusetools.com/docs/fusejs/observable) a thorough read?

You really need to start posting _complete, minimal reproductions_. There is no good way for anyone to answer “how do I access X” without seeing what you do to “X” and where it comes from.

Disclaimer: a _complete, minimal reproductions_ == single-UX-file app that one can copy-paste and run.

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 7:44am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/5 "2017-07-25T07:44:42Z")

</div>

Here is where the data is coming from (SplashPage.js)

```
  var Observable = require('FuseJS/Observable');
  var matric_no = Observable('');
  var password = Observable('');

 function Login(arg){

   var r = '';
   var std_matric = arg.data.matric_no.value;
   var std_pass = arg.data.password.value;

      if(std_pass == '' || std_matric == ''){
	   debug_log('Enter matric/password');
	   //error_empty.value = true;
       }

           r = db.query('select * from student where matric_no = ? and user_password = ?',std_matric,std_pass);
         if(r != ''){
	    router.goto('home',r[0]);
         }else{
	    debug_log('Incorrect Login Details');
	    //error_flag.value = true;
       }		
      }

   module.exports = {
      Login:Login,
      matric_no:matric_no,
      password:password
     }

```

Here is the Home.js

```
   var student = this.Parameter;
   var sqlite = require('SQLite');
   var db = sqlite.openFromBundle('db.sqlite');
   var matric_no = this.Parameter.map(function(param){return param.matric_no});

      function show_result(args){
             var name = args.data.name;
             var semester = args.data.value;
             var sql = db.query('select * from result where matric_no = ?',matric_no);
                     debug_log(JSON.stringify(matric_no));
                     debug_log(matric_no);

       }
       module.exports = {
          matric_no:matric_no,
          show_result:show_result
        }

```

Here is the full code, the value of the **matric\_no** variable is not accessible in the `show_result()` function.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 25, 2017, 7:49am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/6 "2017-07-25T07:49:01Z")

</div>

That is not a _complete, minimal reproduction_ - I can not copy&paste and run it. The keyword is “complete” in this case.

Let me repeat myself: If you’re calling the `show_result()` function before the derived `matric_no` Observable is populated, you might not be getting any value there. It’s populated asynchronously.

And again: Since you’re asking about an Observable, why don’t you first go and give [Observable docs](https://www.fusetools.com/docs/fusejs/observable) a thorough read?

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 8:03am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/7 "2017-07-25T08:03:15Z")

</div>

I have updated the code, please try look into it. I just need to access the `matric_no` variable in other functions after the Observable(this.Parameter) mapping.

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 8:04am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/8 "2017-07-25T08:04:20Z")

</div>

I have gone through that a quite number of times, my answer is not just there I think.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 25, 2017, 8:11am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/9 "2017-07-25T08:11:21Z")

</div>

That is still not a complete, minimal reproduction. Your sqlite query might be failing, you might be calling `show_result()` function before the derived Observable is populated etc. There is no way to help you with the bits of code you’re showing.

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 8:34am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/10 "2017-07-25T08:34:50Z")

</div>

There is nothing I can paste any longer, you helped me with that sqlite query some days ago and they routing and also working fine, the only problem is that I can not access the values of the variables I retrieved from the Parameter in the same JS file.

I need this variable (matric\_no) of the code:

```
  var matric_no = this.Parameter.map(function(param){return param.matric_no});

```

to be accessible in the same file but it’s returning a Fuse.V8.Scripting.object instead of the number ‘2014235020035’ as seen in the debug\_log(JSON\_stringify(matric\_no))

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 25, 2017, 9:12am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/11 "2017-07-25T09:12:35Z")

</div>

It is an Observable, so it is perfectly fine that it’s `Fuse.Scripting.V8.Object`.

Derived Observables are populated asynchronously, as I explained a couple posts ago. Plus, they are only calculated if they are _consumed_, that is - they have at least one subscriber. Since you have added `matric_no` to your `module.exports`, it suggests that there, indeed, is a subscription to it. However, _I don’t see that because you’re not showing how you use it in UX!_

It’s all explained in [Observable docs](https://www.fusetools.com/docs/fusejs/observable#subscribing-to-changes-in-observables).

Try changing your `Home.js` to this:

```auto
   var student = this.Parameter;
   var sqlite = require('SQLite');
   var db = sqlite.openFromBundle('db.sqlite');
   var matric_no = this.Parameter.map(function(param){return param.matric_no});
   matric_no.subscribe(module);

      function show_result(args){
             var name = args.data.name;
             var semester = args.data.value;
             var sql = db.query('select * from result where matric_no = ?',matric_no.value);
             debug_log(matric_no.value);
       }
       module.exports = {
          matric_no:matric_no,
          show_result:show_result
        }

```

So once again: there is absolutely no way to help you if you’re not sharing COMPLETE reproductions. And “there is nothing I can paste any longer” is just a false statement. Yes, you can. You need to prepare a minimal repro that includes both UX and JS code, and holds that in a single-UX-file app.

---

<div class="post-metadata">

**Author:** ![omolewastephen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/omolewastephen/32/289_2.png) [@omolewastephen](https://forums.fusetools.com/u/omolewastephen)\
**Post date:** [July 25, 2017, 9:44am UTC](https://forums.fusetools.com/t/need-a-quick-help-on-this-js/2632/12 "2017-07-25T09:44:08Z")

</div>

Okay. I really appreciate this. Thanks a lot. It has worked, you are a geek.
