You can implement this check by adding a Validation Script to the entitlement selection field in your form. Within the validation logic, use a query on IdentityRequestItem to filter based on requestee identity and entitlement value.
If you get any IdentityRequestItem with above creteria, you can check whether the request item is for add or remove operation. if it is add operation, you can display the message to end user like added entitlement is aleady exist.
Please refer the validationn logic.
<ValidationScript>
<Source>
import sailpoint.object.*;
import sailpoint.tools.GeneralException;
import org.apache.commons.lang.StringUtils;
import sailpoint.tools.Message;
Message msg = new Message();
String identity_id = form.getField("identityName").getValue();
Idenitty identity = context.getObject(Identity.class,identity_id);
if(entitlement != null){
Iterator iterator = context.search("sql: select request_item from spt_identity_entitlement where identity_id = ' "+identity.getId()+" ' and value = ' "+entitlementValue+" ' order by created desc", new HashMap(), null);
while(iterator.hasNext()){
String row = (String) iterator.next();
IdentityRequestItem item = context.getObjectById(IdentityRequestItem.class,row);
msg.setKey("Selected Entitlement already requested. Please select the different entitlement");
}
}
return msg;
</Source>
</ValidationScript>
I have implemented somewhat similar to this but withing workflow step, i am checking the entry in the db for the requested item with few conditions and able to achieve that.