3

Using the Rules module, I would like to have a replacement the is a random string.

I have added a new user field (= some_var, which is a 'Text field' data type), which I would like to change to some random string after the User account is created.

Any ideas or hints to get this to work?

1

There is a (sandbox) module for it, which is the Rules Random module. Here is a quote about it (from the linked page):

A simple rule action to generate either a random string or integer. Can define the length of the random result. For random strings, can also choose to include numbers and lowercase letters.

Either you just use that module, or you look at its source code to understand what it takes to include this logic in your own (custom) module.

With that, all that's needed is to create a custom rule like so:

  • Rules Event: use whatever event that fits your requirements (eg: After saving a new account).
  • Rules Condition: "Entity has field", related to your some_var field. That will make this field available for subsequent processing in Rules Conditions and/or - Actions.
  • Rules Action: Use the action provided by this module, to set a value for your some_var field.
2
  • This is exactly what I need to. I admire your dedication here. It's awesome. I have a question about your answer. How do you download that sandbox? There is no download link or am I missing something? Thanks in advance, Pierre!
    – BassPlaya
    Jul 1 '19 at 8:46
  • Ok. I got it. I can only use GIT to obtain that sandbox module, there is no downloadable link.
    – BassPlaya
    Jul 1 '19 at 8:53
0

There is also another (sandbox) module for it, which is the Rules generate string module. Here is a quote about it (from the linked page):

A simple rule to generate a random string, given optional parameters of length and character set.

Either you just use that module, or you look at its source code to understand what it takes to include this logic in your own (custom) module.

Obviously, creating your custom rule (using the Rules generate string module) is similar to the prior answer: just replace the Rules Action by the one provided by this module.

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.