wrote script to insert but prior check to count rights is not working