Page 1 of 1

Personalized Hash Variables

Posted: Thu May 03, 2018 12:14 pm
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.

Re: Personalized Hash Variables

Posted: Thu May 03, 2018 2:06 pm
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?

Re: Personalized Hash Variables

Posted: Thu May 03, 2018 3:58 pm
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.

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 3:32 am
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

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 5:49 am
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.

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 6:41 am
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#'

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 7:58 am
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...

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 10:18 am
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.

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 8:38 pm
by ahernandez
Thank you so much toms!

Re: Personalized Hash Variables

Posted: Fri May 04, 2018 11:54 pm
by admin
.