Sharepoint 2013 Custom List Edit form Validation:not saving List Item after applying validation on PreSaveAction

Hello,

I am trying to validate sharepoint custom list edit form on the basis of sharepoint  security group on PreSaveAction
my conditions are:
1-If User from 'UserGroup' than it it will ask to fill Request Descripton ,return false
2-if user from other group then it will ask to fill Response description, return false
3- if above condition fullfills then it will  return true

my code(below) is working fine for 1 and 2nd condition but fails to execute 3rd condition?

I am using the below code in script editor Web Part on Edit form.

<script type="text/javascript">
function PreSaveAction(){
debugger;
   var returnval=true;
$().SPServices({
                operation: "GetGroupCollectionFromUser",
                userLoginName: $().SPServices.SPGetCurrentUser(),
                async: false,
                completefunc: function (xData, Status) {
                    $(xData.responseXML).find("Group").each(function () {
                        var groupname=$(this).attr('Name');
//alert(groupname);
var itemTitle = $("textarea[title='Request Description']").val();
var response = $("textarea[title='ResponseDescription' ]").val();
if(groupname=='UserGroup' && itemTitle=='' && itemTitle.length < 1 )
{

   
            alert("Kindly fill the Request Description");
            $("textarea[title='Request Description']").attr("style", "border: solid 1px #ff4c42 !important");
            returnval=false;

}

else 
{
if(response=='' && response.length < 1 )

{

            alert("Kindly fill the ResponseDescription");
            $("textarea[title='ResponseDescription']").attr("style", "border: solid 1px #ff4c42 !important");
            returnval=false;

}
}

return returnval;


   });
                }
            });

        }

</script>





May 29th, 2015 1:22am

Hi,

Per my understanding, you might want users fill different fields based on the group they belong to.

As a common practice, I suggest debug the code in browser and make tests with different accounts to go through each possible scenarios of the code logic, it will make you easier to find out the issued line of code. 

About how to debug JavaScript using IE Developer Tools for your reference:

https://msdn.microsoft.com/library/bg182326%28v=vs.85%29?f=255&MSPPError=-2147217396

Feel free to reply if there is any progress.

Thanks
Free Windows Admin Tool Kit Click here and download it now
May 31st, 2015 1:19am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics