Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Browse&Edit form to only show the current users information

Questions related to using nuBuilder Forte.
Post Reply
MLeggy
Posts: 7
Joined: Mon Jul 13, 2020 4:23 pm

Browse&Edit form to only show the current users information

Unread post by MLeggy »

Hello,

I am creating a simple time sheet application. 1 master table with a few lookup tables. What I am struggling with is getting the Timesheet Browse&Edit form to only show the current users logged times.
form.jpg
Any assistance would be appreciated.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Browse&Edit form to only show the current users informat

Unread post by kev1n »

Hi,

I would do it like this:

When saving the form, you store the user id in a field/db column (e.g. user_id)

In the form's custom code, add this JS:

Code: Select all

function nuBeforeSave() {

	let userId = nuCurrentProperties().user_id;
	$("#user_id").val(userId).change();

    return true;
}

In the Browse SQL, add a Where clause like

WHERE user_id = '#USER_ID#'

Let me know if you need more details.

Edit: Here's a more secure way to achieve that: https://github.com/smalos/nuBuilder4-Co ... o_own_data
Last edited by kev1n on Sun Jul 19, 2020 4:18 pm, edited 2 times in total.
MLeggy
Posts: 7
Joined: Mon Jul 13, 2020 4:23 pm

Re: Browse&Edit form to only show the current users informat

Unread post by MLeggy »

Worked perfectly thank you.
david2929
Posts: 4
Joined: Mon Aug 24, 2020 11:16 am

Re: Browse&Edit form to only show the current users informat

Unread post by david2929 »

Hi,

I am using the
"Edit: Here's a more secure way to achieve that: https://github.com/smalos/nuBuilder4-Co ... o_own_data" solution.

And my case is a little more complicated. And the current USER_ID value is not going into the field in the table. Can you please help me? Thank You!

It is a browse and edit form. it joins table device_list with group_list (a lookup table), so that the group_desc can be displayed with other fields from device_list.
I follow the above solution. All goes well, but the current USER ID value is not filled into the user_id of device_list.
You do not have the required permissions to view the files attached to this post.
david2929
Posts: 4
Joined: Mon Aug 24, 2020 11:16 am

Re: Browse&Edit form to only show the current users informat

Unread post by david2929 »

You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Browse&Edit form to only show the current users informat

Unread post by kev1n »

Hi,

Use nuHasNoRecordID() instead of nuHasNewRecordID().

In AS, add

Code: Select all

nuDebug("UPDATE device_list SET user_id = '#USER_ID#' WHERE device = '#RECORD_ID#' ");
and check the nuDebug Results to see what the generated SQL looks like.
benritter
Posts: 49
Joined: Wed Aug 26, 2020 10:38 pm

Re: Browse&Edit form to only show the current users informat

Unread post by benritter »

Hi, I'm trying to use this function and the user_id field in my table is always null. So when logged in as a user, not globeadmin, the browse is empty. I can see the zzzzsys_user_id is there. But this php is not adding the user_id to my "client" table.
Here's what I'm seeing:
Screenshot 1.png
Screenshot 2.png
Screenshot 3.png
You do not have the required permissions to view the files attached to this post.
benritter
Posts: 49
Joined: Wed Aug 26, 2020 10:38 pm

Re: Browse&Edit form to only show the current users informat

Unread post by benritter »

I think I fixed it. The github page says to use "nuHasNoRecordID" but the Discord code library says to use nuHasNewRecordID". the latter worked for me.
Post Reply