Page 1 of 1

Browse&Edit form to only show the current users information

Posted: Tue Jul 14, 2020 11:28 am
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.

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

Posted: Tue Jul 14, 2020 12:04 pm
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

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

Posted: Tue Jul 14, 2020 1:04 pm
by MLeggy
Worked perfectly thank you.

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

Posted: Mon Aug 31, 2020 4:13 pm
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.

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

Posted: Mon Aug 31, 2020 4:20 pm
by david2929

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

Posted: Tue Sep 01, 2020 4:07 am
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.

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

Posted: Fri Sep 18, 2020 8:04 pm
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

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

Posted: Fri Sep 18, 2020 8:22 pm
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.