Check for person prior to save
-
07-01-2021 - |
Pregunta
I have a SharePoint form (not in InfoPath) that can be created by numerous personnel. In order for us to accept a request, the form must have acceptance from two people--one inside our shop, one outside. I want to create a validation in the column of "OPS Support Decision" that requires "accepted"--a drop down, if the current user belongs to OPS. If the form is being created by someone outside of OPS, then the "Element Support Decision" would require "accepted"--a drop down as well, if the user is outside of OPS. I am willing to write the code, but this certainly is not like excel...and I am lost! Any help is greatly appreciated.
Solución
You can do this. There is a function is SPServices that will allow you to check if a user belongs to a certain permissions group. You can check this on DocReady then apply your logic to the form to set the value of the dropdowns, hide/show, or whatever logic you want.
<script type="text/javascript" src="/_layouts/js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="/_layouts/js/jquery.SPServices-2014.01.js"></script>
<script type="text/javascript">
$(document).ready(function(){
isGroupMember("Your User Group", function(result){
if(result){
//do your ddl logic here or write a separate function to call here
}
});
});
function isGroupMember(groupName, callback)
{
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: true,
completefunc: function(xData, Status) {
callback( !!($(xData.responseXML).find("Group[Name='" + groupName + "']").length) ); /* returns bool */
}
});
};
</script>