I've a Leave form in SharePoint list. when a female logins with her credentials, she can be able to see 'Maternity leave' drop down. Whereas, when a male candidate logins with his credentials, he should not be able to see 'Maternity leave' from drop down option. Can any one please help how to differentiate the gender using Js/ Jquery? (Based on Current logged in user)
-
2I don't believe you can unless you've pushed that information out from your AD (or other system) into your User Profile Service. Why not just have a field that says "Maternity/Paternity"? Or even better, just a field that says Parental Leave which encompasses Maternity Leave, Paternity Leave, and Adoption Leave.– KGlasierCommented Aug 23, 2019 at 14:54
-
2this seems like a bad idea for a number of reasons. I'd go with @KGlazier's approach– Derek GusoffCommented Aug 23, 2019 at 14:55
2 Answers
I'm going to flesh out my comment as an answer, because I find your approach to be bad for a few reasons... As @Derek Gusoff mentioned.
First: Parental Leave
As outlined in the "Parental Leave" section, I'd recommend using 'Parental Leave' in place of Mat/Pat leave, as it's more all encompassing and doesn't require filtering based off gender.
Shotgut to kill a fly
Unless you have a business case that requires you to separate out maternity and paternity leaves, and filter them out based off gender, you're looking at a much more complicated form than it needs to be. Solutions like this are in essence 'overkill' in that they could be done my much simpler means.
Overhead Loading
The more JS you add to your page, the more work the browser has to do before the page is loaded and the form is ready to use. Adding one small thing like checking gender may not seem like much, but that sort of mentality can lead to slow loadtimes after adding dozens of other "small" scripts that slow down the whole site. If your solution can be done effectively without JS, try to do that. Sometimes less is more.
Biasing/Discrimination Issues
We're regularly seeing people identify as a gender other than what their sex implies. As a result, someone who you'd typically think falls under maternity leave may wish to request paternity leave as they believe it more accurately represents who they are. In the end, maternity and paternity leave tend to be the same thing with different names anyway, so why make your employees choose? Any why pigeon hole them into whatever category you think they are. I'm not sure what your work situation is like over there, but this may be a factor.
Simpler Solutions
There's a few things you could do instead of using JS. Such as one field for each ("Mat/Pat leave", "Maternity/Paternity", etc), or use the generic term "Parental Leave" instead.
Create a checkbox that your user can request (Male, Female, Other) and have the leave display based off the selection. (simpler, but may still require some coding depending on your platform)
If you need statistics on the two separate types, then leave them separate. Don't filter them, just leave it as Maternity
, Paternity
, Sick
, ...
etc. Then you're not pigeonholing anyone.
In theory you can do this if you have gender field in AD and this field is mapped in SharePoint User Profiles services.
Then you can customize the form and add js code(also you can use CSR).
But I don't recommend to do this requirement. Because not only females can have maternity leave.