Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Personalized Hash Variables

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Locked
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Personalized Hash Variables

Unread post by ahernandez »

Hi,

Is there a way to create new Hash variables to store common information for my app and use it in the sql statements?

I would like my app could manage multi companies and this could help me.

Thanks in advance.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Personalized Hash Variables

Unread post by toms »

Hi,

There's a function nuSetProperty(). The property can then be used as a Hash Cookie.
https://wiki.nubuilder.cloud/ ... etProperty

Can you provide more details on what you're trying to accomplish?
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Personalized Hash Variables

Unread post by ahernandez »

Hi toms,

All the tables have a field called company_id and there is another table associating user_id with company_id in such a way that I would like that the users could only see the records of their company.

I tried to insert PHP code in BE section of Launch to run sql statements and get the company_id for the logged user and store it in a $GLOBALS var, but it doesn't work and when I try to access to these $GLOBALS from BB in the Form the data doesn't exists.

Thank you.
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: Personalized Hash Variables

Unread post by admin »

ahernandez,

There are some preset Hash Cookies you can use in a Form's Browse Tab SQL.

https://wiki.nubuilder.cloud/ ... sh_Cookies
brsql.PNG
Your SQL in could be something like...

Code: Select all

SELECT * FROM clients WHERE salesperson_id = '#USER_ID#'

Steven
You do not have the required permissions to view the files attached to this post.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Personalized Hash Variables

Unread post by ahernandez »

Hi,

I know those Hash Cookies. The question is if I could create my own Hash Cookies.
I think it would be the soluction, otherwise what other ways are to do something similar?

Thank you.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Personalized Hash Variables

Unread post by toms »

ahernandez wrote:Hi,

I know those Hash Cookies. The question is if I could create my own Hash Cookies.
I think it would be the soluction, otherwise what other ways are to do something similar?

Thank you.
Yes with nuSetProperty() - see my first reply.

But a query, something like this, should do the job:

Code: Select all

SELECT table.* FROM table 
INNER JOIN company 
ON table.company_id = company.company_id
WHERE company.user_id = '#USER_ID#'
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Personalized Hash Variables

Unread post by ahernandez »

Hi toms,

I think it won't work...

I will try to explain. I don't speak a good English. Sorry.
I need to get the g_company_id value from a table accessing with #USER_ID# in BE PHP section before Launch Form using SQL like you said.

This is the code in that section..

$g_user_id = nuHash()['USER_ID'];

$s = "SELECT * FROM employee WHERE epl_user_id = '" . $g_user_id . "'";
$t = nuRunQuery($s);
$r = db_fetch_row($t);

$g_company_id = $r[1];


I would like to store this g_company_id value in a hash coockie for to be used in the SQL Statements for browse every form launched from this Launch Form.

By the moment I have solved this including a SELECT inside WHERE CLAUSE but I don't like pretty much...

SELECT
customer.*
company.*
FROM customer

LEFT JOIN company ON com_company_id = company_id

WHERE com_compnay_id = (SELECT epl_compnay_id FROM employee WHERE epl_user_id = '#USER_ID#')

I would like something like this...

WHERE com_compnay_id = '#g_company_id#'

Thank you toms and admin for listening and answer...
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Personalized Hash Variables

Unread post by toms »

To my knowledge there is no function to add a (global) Hash Cookie that is valid in all forms.
I asked for the same in another topic but no solution was offered.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Personalized Hash Variables

Unread post by ahernandez »

Thank you so much toms!
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: Personalized Hash Variables

Unread post by admin »

.
Locked