Discussions

 View Only
  • 1.  Can I access system variables through javascript?

    Posted 11-01-2018 20:50
    I have a couple of Variables set up under Home/Settings/Variables and I would like to use their values in creating a new record using a button on the home page.  The home page buttons offer limited choices (New Record, Report, Page & URL), so I don't know how to write successive API calls in any of those formats to accomplish my goal.  How can I do API_SetDBVar & API_GetDBVar calls from the home page?


  • 2.  RE: Can I access system variables through javascript?

    Posted 11-01-2018 21:40
    >Can I access system variables through javascript?

    Of course you can! JavaScript can access everything and is your portal to a happy, bountiful and successful life.

    In the pastie below I define a function with the following signature:
    getDBVar(dbid, varName) { ...}
    When you call it a promise is returned which when it resolves returns the value of the varName.

    In the Pastie Database I created a new application variable foo and gave it the value bar. So if you visit the Pastie Database and paste the code into the console you will get the following output:
    foo = bar
    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=680

    Notes:

    (1) This script is written in a very specific style to make the code as short as possible and uses some advanced JavaScript features including ES6 Promises.

    (2) The script converts the jQuery promise to an ES6 promise to get around a bug in jQuery 1.71 which QuickBase uses which prevents proper chaining.

    (3) The coding for setDBVar would be very similar but would use a function with the following signature:
    setDBVar(dbid, varName, varValue) { ...}


  • 3.  RE: Can I access system variables through javascript?

    Posted 11-02-2018 13:55
    Thank you!  I appreciate your help!


  • 4.  RE: Can I access system variables through javascript?

    Posted 11-14-2018 15:47
    Dan - I have succeeded with 'GetDBVar', but my limited knowledge is preventing me from translating that to 'SetDBVar'.  Here's what I've got.  Where am I going wrong?

    function setDBVar(dbid, varDaName, 12) {
    return Promise.resolve(
    $.set(dbid, {
    act: "API_SetDBVar",
    varname: varDaName
    })
    ).then(function(xml) {
    return $("value", xml).text();
    });
    }

    getDBVar(dbid, varDaName)
    .then(function(varValue) {
    console.log('${varDaName} = ${varValue}');
    });

    Thank you!

    Ken


  • 5.  RE: Can I access system variables through javascript?

    Posted 11-14-2018 18:26
    function setDBVar(dbid, dbvName, dbvValue) {
      return Promise.resolve(
        $.get(dbid, {
          act: "API_SetDBVar",
          varname: dbvName,
          value: dbvValue
        })
      ).then(function(xml) {
        return $("value", xml).text();
      });
    }
    var dbid = "";
    var dbvName = "";
    var dbvValue = "";
    setDBVar(dbid, dbvName, dbvValue)
      .then(function(dbvValue) {
        console.log('${dbvName} = ${dbvValue}');
      });


  • 6.  RE: Can I access system variables through javascript?

    Posted 11-14-2018 20:58
    Thank you!  I got it to work, and tried getting the 'Set' and a 'Get' to work in sequence and then nothing worked!  I'll have to play with it more tomorrow, but thank you for your help.


  • 7.  RE: Can I access system variables through javascript?

    Posted 11-15-2018 18:19
    It's all working now!  Thank you so much for your help.


  • 8.  RE: Can I access system variables through javascript?

    Posted 11-16-2018 08:54
    Go Script!