I have this button:
<a id="customAddNew" href="/ibs/_layouts/listform.aspx?PageType=8&ListId={CED7A37E-B1B4-46DD-B5C6-9232195D7E16}&RootFolder=" target="_self">Submit Work Order</a>
I'm trying to use this script to hide the button based on the user logged in:
script type="text/javascript">
var email = $().SPServices.SPGetCurrentUser({
fieldName: "EMail",
debug: false
});
var trimmedEmail = email.split("@");
var newButton = document.getElementById("customAddNew");
if (trimmedEmail[1] == "napacanada.com"){
//Is NAPA User, which can't Add New Items
alert("napa user");
newButton.style.display = "none";
//$('#customAddNew').attr("display","none");
alert("check point")
}else{
//Is City User, can Add New Items
alert("none napa user");
newButton.style.display = "block";
//$('#customAddNew').attr("display","block");
}
</script>
I've tried doing it using JavaScript and jQuery but neither worked. This is the error I get:
Cannot read property 'style' of null
The first alert runs fine depending on the user, just not the check point alert