Hello,
As per our check, the script works as intended and takes into account such cases. Please, post here or send us (support@adaxes.com) in TXT format the script you are using. Also, please, provide all the possible details about the workflow where the script is executed. Screenshots of the corresponding business rules will be much appreciated.