5

On creating a "course" content, i am creating a dummy user as its "instructor". Here is the related question.

I wasn't able to add a condition to the rule that creates the user, that checks whether a user with that name already exists. If it does, then the action (create new user) will not fire.

How can I do that?

I am using rules module with drupal 7.

4

You need add the condition for if the user exists or doesn't exist and then you are able to create two actions, depending on the user exists or not.

The problem is that this is not possible to do with Rules out of the box. It's not hard to add a condition like this, but it required custom code in a custom module. If this is not an option, what you are asking for is impossible AFAIK, as it doesn't exist.

| improve this answer | |
4

In Rules 7.x-2.2, checking if a user exists is possible with no custom coding. See the Rules maintainer's explanation

To check if a user exists, use the following:

  1. Condition: "Entity exists by property
  2. Entity Type: "User"
  3. Property: "Name" (or any other user field);
  4. Value: "instructor name" (based on your related post; otherwise this would be the ).
  5. Negate this condition. (so that the rule will not fire if a user exists)

This can be done either in one reaction rule or as an e.g. "condition" component. If using the component, it's vital to pass the node object to the component (in component settings) as a variable so that "instructor name" is available in the component.

As I noted in your related question that you will almost always want a prior condition that ensures the content type in question contains is of type "course". Otherwise, this rule will run when you either may not want it to or it should not run.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.