Are you trying to set it to the lowest slot available like when you drop it outside the inventory or are you saying you want it to snap back to the slot it was just in?
To pick the lowest slot available think about it, you need to apply the logic 'pick slot with lowest number that is not occupied' in this scenario, same as when you drop it outside the inventory. Instead under the isOccupied check you replace 'slotnumber = invslot.number' with the 'pick slot with lowest number and is not occupied' condition.
If the expected behaviour is the latter that it snaps back to the slot it was just dragged from the problem is to do with inventory slots being picked. In the events you have narrowed it down to pick the invslot you are overlapping and only this, so you cannot then pick the previous invslot it was assigned. To fix this you open up the instances again to be picked by adding a 'Pick all invslots' condition above the condition you have now. This will then allow it to pick the previous invslot based on item variable.