Excluding certain records from search forms for certain users?

Our Engineering dept wants to have a “Released” field which, if left unchecked, prevents other departments from seeing or using the part at all. I’ve created a Released_c field and an In-Transaction directive which causes an error if a non-engineer enters it on a form, but I can’t figure out how to make unreleased parts only show up in search forms for Engineering.

I’d like to replace the default Part Search with a quick search that has a Released checkbox checked by default, and then set to read-only for non-Engineers. That way Engineering users can un-check the box to search for unreleased parts while everyone else is stuck with only Released. Unfortunately, I can’t figure out how to set the default value of a checkbox in Quick Searches (or set it to read-only based on security group). Is this possible? Or is there another way?

You can replace the search using Quick Search as you stated (remove the checkbox) and if engineers want to search differently they can click “BASE SEARCH” or use a different quick search that is available to them. Requires you to teach them how to switch searches but that’s not difficult.

That makes sense. It occurs to me now that other users would also be able to figure that out, though, so I don’t think quick searches are the solution here. Is there some other way to hide certain parts from certain users?

You could put a post processing BPM on Part.GetList (this is what normal search calls) and remove the parts from there based on security group. But this would require custom C# BPM

Nice! I’ll see if I can figure out the C# part, but that sounds perfect. Thanks!

Any reason you’re not using the “Hold” feature on Part Maintenance? While restricting the search provides security through obscurity, if someone knows the part number, then could just enter it and do whatever they like. You can still hide items in the search using the Hold field but Hold will also prevent sales orders and warn if purchasing tries to but the part.

Just a thought…

Mark W.

Do you mean the OnHold field? That field seems to prevent Engineering from working with a part-- they want to be able to run jobs, purchase materials etc. for unreleased parts without exposing those parts to the rest of the company. We’re a biomedical company, and there’s a lot of regulatory hoops that engineering is trying to avoid jumping through until they’re actually ready to release a part.

Also @josecgomez , I have one last question: I found a section in the programmer’s guide that seems relevant:

So I created a Condition box that checks if a non-engineering user is triggering PArt.GetList, then runs this custom code:

var releasedOnly = from a in Db.Part
where a.Released_c == true
select a;

this.dsHolder.Attach(releasedOnly);

This causes an error stating that the script does not contain a definition for dsHolder. I also tried replacing dsHolder with ttPartList, but then it told me ttPartList does not have a definition for Attach(). Do you know what I need to declare, and how to declare it?

In this case you should be able to just loop through ttPart and Delete() the records you don’t want… Or better yet, I believe that the GetList() takes a whereClause as a parameter, you could add an additional condition to the whereClause on preprocessing based on Security Group… something like

Condition: If User not in Group XXX
Action whereClause = whereClause + " AND Relase_c=1"

See if that works first :slight_smile:

1 Like

That sounds good, but I must be missing something. I entered that line–
whereClause = whereClause + “AND Release_c = 1”;
–but when I test it by running Part Search with a non-engineering user account, I get an error message saying “Incorrect syntax near =”.

Is release_c a number field or nvarchar? if it’s nvarchar you’ll need to surround the 1 with '.

Release_c = ‘1’

Also, If the whereclause is expected to already have data, you may want to add a space:
whereClause = whereClause + “ AND …

You’ll need a space between " and"

Added the space, now it says “incorrect syntax near the keyword “AND”.”

Also, this “whereClause = etc” line is the only line I have in the Execute Custom Code box. Is there something else I was supposed to include? Any usings or references?

can you even query “UD” fields in list lookups?

No that’s fine, so if the whereClause is empty you ca’nt do " AND" you’ll hve to do some conditional logic

You can in 10

If there isn’t already data in the whereclause, just remove the AND all together and set the whereclause like:
whereClause = "Release_c = 1”;

!!! I got it to work! I just removed the AND so that it’s just:

whereClause = “Released_c = 1”;

This isn’t a perfect solution (it overwrites any other where clauses in Part Search) but it works for what I need!

Lol…looks like I beat you by a split second

Chris gets the gold, but I get functioning code so I’m still pleased. :stuck_out_tongue:

1 Like

I said to remove the “AND” and add some conditional logic like an hour ago :roll_eyes: I should get the gold! … but who’s counting…
all joking aside, you should just check to see if there’s data in the whereClause and if there is use the " AND" otherwise don’t. Because I am betting your users will type something in that box and get pissed if it gets eliminated.

Something like this

whereClause = string.IsNullOrEmpty(whereClause) ? "Released_c = 1" : " AND Released_c=1";