0

storing system variables

I worked out a way of storing named global variables using a GLOBALS table and two global scripts. 

If this is of any use to anyone, I would be happy to post my solution. 

5 replies

null
    • John_Halls
    • 1 yr ago
    • Reported - view

    Hi Louis

    Yes please! Always interested to see what other developers have come up with.

    Regards John

    • NYNNA
    • Louis_Cornacchia
    • 1 yr ago
    • Reported - view

    The scripts and field descriptions are below. 

    I use this to store text values during the session, but it can apply to any field type. 

    let result = setGlobal( globalName, value)  

    let result = getGlobal(globalName)

     

    The key is to bind storedGName at the server  and     bind storedGValue at the browser (local memory) in the table named GLOBAL. 

    The values are stored in a table called Globals. 

     

    #{//}#;
    #{//}#;
    #{//}#;
    #{// *******************************************************}#;
    #{// *****************  FUNCTION Set Global  ***********************}#;
    #{// *******************************************************}#;
    #{//}#;
    function setGlobal(gName : text,gValue : text) do
        let xResult := "";
        let xFind := "";
        let xCnt := 0;
        let xGName := lower(gName);
        let xGValue := gValue;
        if gName = null then
            let xResult := "error - gName empty.";
            xResult
        else
            let xCnt := cnt(select globals where storedGName = xGName);
            if xCnt = 0 then
                #{// if null, then no record was found so create one and store the global name and value.*}#;
                let p := (create globals);
                p.(storedGName := xGName);
                p.(storedGValue := xGValue);
                #{// *alert("A xResult is null" + xResult + "<< (Null)");**}#;
                "ok -A"
            else
                #{// if not null, then a record was found so store the global value.*}#;
                let xFind := last(select globals where storedGName = xGName);
                xFind.(storedGValue := xGValue);
                #{// *alert("xResult**=" + xResult + "<<(not null)");**}#;
                "Ok -B"
            end
        end
    end;
    #{//}#;
    #{//}#;
    #{// *******************************************************}#;
    #{// *****************   get Global  ***********************}#;
    #{// *******************************************************}#;
    function getGlobal(gName : text) do
        let xGName := lower(gName);
        let xResult := "";
        let xCnt := 0;
        if gName = null then
            xResult := "error - gName empty.";
            void
        else
            xResult := last(select globals where storedGName = xGName).storedGValue
        end;
        xResult
    end;
    #{//}#;
    #{//}#;
    #{//}#;

      • NYNNA
      • Louis_Cornacchia
      • 1 yr ago
      • Reported - view

       code needs a bit a cleanup. eg., there is no need for xCnt in getGlobal function

    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    Nifty, thanks 👍

    • checkyourmirrors
    • Matthew_Moran
    • 10 mths ago
    • Reported - view

    Do you have a sample database I can see this working in?

Content aside

  • 10 mths agoLast active
  • 5Replies
  • 165Views
  • 4 Following