Skip to Content
Technical Articles
Author's profile photo Abimanyu G

Rules and Validations in SAP C4C

Hello everyone!

This blog post focuses on the SAP Cloud for Customer Rules and Validations.

Ruby script is used to write rules, which is made simple by a set of operators and functions. It help make fields visible, read-only, mandatory, change color and to assign default values.

We’ll see examples for each of the functions and operations here.

To write a rule or validation do the following,

  1. Enter into Adaptation Mode
  2. Go to Implementation option by clicking on Back arrow till last.
  3. Then select Implementation and Rules and Validation

Rule Writing Screen:

  1. Left side you can find all the fields that are available in the current business object.
  2. Center you can write your code.
  3. Right side you can find operation, functions, colors that can use in your code.

Rule Type:

We have two types of rule,

  1. Property
  2. Value



Syntax for all the Functions:

You can also use ‘1’ for true and ‘0’ for false

Logical Operator:

1. IF() -> Evaluates the logical expression, if the outcome is true, return the first value, else return the other value 

Syntax: IF(logical_expressions, value_if_true, value_if_false)

Example: IF(Root.Status == ‘01’, true, false)

2. AND() -> all the condition should be true. Output is a Boolean value; TRUE if all values are true, and FALSE if one or more values are false. 

Syntax: AND(logical_expression1, logical_expression2, … )

Example: IF(AND(Root.Status == ‘01’, Root.Source == ‘02’), true, false)

3. OR() -> any one condition should be true. Output is a Boolean value; TRUE if any expression is true, FALSE if all expressions are false.

Syntax: OR(logical_expression1, logical_expression2, …)

Example: IF(OR(Root.Status == ‘01’, Root.Source == ‘02’), true, false)

4. NOT() -> NOT reverse the truth value of its operand. Output is FALSE for TRUE and TRUE for FALSE.

Syntax: NOT(logical_expression)

Example: IF(NOT(Root.Status == ‘01’) , true, false)

5. CASE() -> Returns result 1 if condition 1 is satisfied, returns result 2 if condition 2 is satisfied, and so on

Syntax: CASE(logical_expression1, result_1, logical_expression2, result2 … )

Example: CASE(Root.Status == ‘01’, true, Root.Status == ‘02’, false, Root.Status == ‘03’, 1,                    Root.Status == ‘04’, 0)

Date and Time:

1. DAY() -> Returns the day component of a date (if the date is October 28, 2016, the system returns 28).


    • IF(DAY(Root. StartDate) == DAY(Root.LastChangeDate), true, false)
    • IF(DAY(Root.StartDate) == 9, false, true)

2. MONTH() -> Returns the month component of a date in number (if the date is October 28, 2016, the system returns 10).


    • IF(MONTH(Root.StartDate) == MONTH(Root.LastChangeDate), true, false)
    • IF(MONTH(Root.StartDate) == 6, true, false)

3. NOW() -> Returns the current date and time in the format 2022-06-09T09:08:26.676Z.

4. TODAY() -> Returns the current date in your time zone.

Example: IF(Root.CreationDateTime == TODAY(), true, false)

5. WEEKDAY() -> Returns the day of the week in number(1=Sunday, 2 =Monday, and so on).

Example: IF(WEEKDAY(TODAY()) == 1, true, false)

6. YEAR() -> Returns the year component of a date (if the date is October 28, 2016, the system returns 2016).


    • IF(YEAR(Root.CreationDateTime) == 2022, true, false)
    • IF(YEAR(TODAY()) == 2022, true, false)


1. BOOL() -> Converts a character to a Boolean value; output is TRUE if there is a value, FALSE otherwise.

Example: IF(BOOL(Root.BusinessPartnerCreatedIndicator), true, false)

(refer this screenshot for below text function examples)

2. CONTAINS() -> Evaluates two arguments of text and the output is a Boolean value; TRUE if the second text contains the first text; if not, the output is FALSE.

Syntax: CONTAINS(‘find_text’, within_text)

Example: IF(CONTAINS(‘is’, Root.Note), true, false)

3. FIND() -> Returns the position of the first occurrence of the text within the text. Position value starts with index 0.

Syntax: FIND(‘find_text’, within_text)

Example: IF(FIND(‘i’, Root.Note) == 2, true, false)

4. LEN() -> Output is the number of characters in a specified text string.

Syntax: LEN(text)

Example: IF(LEN(Root.Note) == 19, true, false)

5. TEXT() -> Converts a value to a text.

6. TOLOWER() -> Converts a text string to lowercase.

7. TOUPPER() -> Converts a text string to uppercase.

8. TRIM() -> Removes the spaces and tabs from the beginning and end of a text string.

9. SUBTEXT() -> Retrieves part of a main text based on offset and length.

Value Information:

1. ISNUMBER() -> Evaluates if a text value is a number; output is TRUE if the text is a number, else it is FALSE.

2. ISBLANK() -> Evaluates if an expression has a value; the output is TRUE if it is blank; the output is FALSE, if it contains a value.

Special Function:

1. CLIENTTYPE() -> Returns FIORI when the client type is Fiori client, and HTML5 when it is HTML5.

2. DEVICETYPE () -> Returns DESKTOP, TABLET, or PHONE depending on the device type used.

3. ISOFFLINE() -> Returns TRUE if the solution is offline, and FALSE when connected.

4. MYUSERROLES() -> Returns one or more business role IDs assigned to the current logged-in user

Syntax: MYUSERROLES()==’Business Role ID’

Example: IF(MYUSERROLES()==’admin’), true, false)

5. GETUSERNAME() -> Retrieves the user’s name of the current logged in user.

You can combine two or more function in single rule. That is totally depends on the requirement.

Font Color Rules:

C4C support six pre-defined colors to change the look and feel of your user interface.

Syntax: IF(logical_expressions, color_if_true, color_if_false)

Example: IF(Root.Status == ‘01’, ‘GOOD_DARK’, ‘BAD_DARK’)

Default Value Rules:

This rule works only in the Quick Create screen of any business objects.

When working with default values, there are a few things to keep in mind.

  • Value Type rules are applicable only on Quick Create screens
  • The return value must be enclosed in single quotes
  • Unless you wish to choose the return value from a different field, in such case you’ll just choose that field in the rule without single quotes.

To write a default rule, first we have the change the rule type as Value like below,

Syntax: IF(logical_expressions, ‘default_value’, ‘blank’)

Example: IF(Root.UseExistingAccount, ‘This lead is created using existing account’, ‘ ‘)

If existing account is selected, then in Note field it will display the “This lead is created using existing account”.

We have to assign this to the field where we want to display the default value.

Select the field in Adaptation Mode, select Rule under Set Default Value. It will display the default rule list that you have created. Choose it and apply it.


C4C has one more cool feature that is called Validations.

We have three level of Severity.

  1. Error -> it shows a message with error symbol and wont allow us to save.
  2. Warning -> it shows a message with warning symbol and we can save.
  3. Information -> it simply display some message with information symbol.

Validation will work only with the existing rule. So, before creating a validation, a rule is must.

Example: If lead source is Referral, then we should display a warning message.

Below is my rule,

Now create validation like below,

Note: All of the above are just examples. You won’t be able to improve at rule writing unless you give it a try.

Change Logs:

Refer the Comment link to get more detail about Change logs.

My Other Blogs:

I hope that this blog post has given you some insight into SAP C4C rules and validation. Kindly like and follow to get more detailed blogs.

See You Soon👋🏻,

Abimanyu G

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Teresa Sanchez
      Teresa Sanchez

      Very useful post! Thank you for the information

      I would like to ask something related, I am trugling with a rule for fields that should be read only according some conditions (for example for no prospect accounts) however if the user has ADMIN business role should be able to modify (for this MYUSERROLES). I tried several rules with OR without success. Could you give me any tip please?

      Thank you!


      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Hey Teresa,

      Your condition is, if account role is not prospect and user role is admin, then they can able to edit the field. Else no one allowed to edit the field.

      If above condition is right then you can use any of the below rule,

      IF(AND(Root.Role != "BUP002", MYUSERROLES() == "Admin_Business_Role_ID"), true, false)

      BUP002 is a code value for Prospect.

      If the Role field in the Account does not equal Prospect and the current login user role is ADMIN, then this rule will triggered

      IF(AND(NOT(Root.ProspectIndicator), MYUSERROLES() == "Admin_Business_Role_ID"), true, false)

      If the Prospect Indicator in the account is false and the current login user role is ADMIN, then this rule will triggered


      Kindly confirm on the comment if it is working and share this blog with your connections.😊



      Abimanyu G

      Author's profile photo Teresa Sanchez
      Teresa Sanchez

      Hi Abimanyu G,

      Thank you so much for the information provided. It has been very helpful.

      Finally I used the second Rule but I did some update for my case (when the account is not a prospect, some fields should be read only, however those fields should be editable if the user has business role Admin)

      IF(AND(NOT(Root.ProspectIndicator), MYUSERROLES() != "Admin_Business_Role_ID"), true, false)


      Hope this can help more people!

      Thank you,


      Author's profile photo Alexander Maier
      Alexander Maier

      Hi Abimanyu,


      i have a question to this topic.


      I need a validation rule for readonly but not only for one Userrole.


      I should check that some fields are readonly if account role is not prospect and User role are one of 5 different roles. But for all other the field should be editable.

      We have round about 40 roles and only round about for 6 should get the field readonly.


      I have checked several options but it doesnt work if i test with the role it looks ok but if i checked another role then the field is also readonly.

      For this roles and account not prospect should the field readonly. For all other editable.



      I have checked some of conditions f.example this one


      Hopefully you can help me.


      Best regards



      Author's profile photo Sathish Ganesan
      Sathish Ganesan

      Hi Abimanyu,


      Very useful post. I have a requirement where we need to force user to enter comments in a field whenever they change the 'Assigned To' field value to a value different than current value. For this I can create an extension field to add comments and make it visible and mandatory by a rule but how do I set the condition on the rule to track change in field value of 'Assigned To'.

      Thanks for your help in advance.



      Author's profile photo Brad Vukich
      Brad Vukich

      Great post Abimanyu G! I appreciate the thoroughness in your description of function parameters, as well as the font color option codes.

      I have a question about tracking changes to rules. When I modify a rule, does the change get logged in history anywhere? My team is looking to gain more clarity as to when changes were made and if we're able to determine the logic before and after the change.


      - Brad

      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author
      Hi Brad,
      Yes it is. Every time we modify a rules, the Changes log will get updated in the below,

      1. Changes tab in Adaptation mode. we can see that changes in details by clicking the (right and left) arrow icon.

      2. Administrator WC -> General Setting WCV -> Layout Change History (Filter the Type column with AddBusinessLogic.

      And if you open any one in the list, it will display like below.

      And in top right we have Delete option to delete the logic. It will delete the changes in the particular field.

      Note: But in both the case, we can only see the change done by whom, where and its description. We can't the see the rule code.

      Kindly confirm if this reply clarifies your question.


      Abimanyu G

      Author's profile photo Brad Vukich
      Brad Vukich

      Thank you for the details Abimanyu, it's exactly what I wanted to know.


      Author's profile photo Former Member
      Former Member

      Hey Abimanyu G,


      great article!


      • Do you know if it possible do define a rule based on the warranty end date of a registered product? (If the warranty end date is in the history than field XY should be in another color.)


      I cant find this attribute in the selection.


      Many thanks in advance.




      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Hey Former Member, 

      Sorry. Please explain the question once more. A screenshot will helpful.


      Author's profile photo Former Member
      Former Member

      Hey Abimanyu,


      I was able to find the correct variable by using the debug mode.


      Thank you.



      Author's profile photo Martina Bednar
      Martina Bednar

      Hello Abimanyu G

      thank you for your blog post. Its wonderfull!

      Do you know by chance if there are date calculations also possible linke now()+7days =?

      It is possible on UI Flied calculations and also Workflows formula, but I was not able to do it in UI Rule Editor.


      Thank you & br.


      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Hello Martin

      Sorry for the delayed response.

      In KUT adaptations, this kind of rules is not possible. As you mentioned, it can be done by using workflow field update.

      Best Regards,

      Abimanyu G.

      Author's profile photo Former Member
      Former Member

      Hi Abimanyu G:

      Hope you are doing well. Any chance you can help me with this one?

      I need to write a rule to avoid edition of specific fields dependind on the status of a ticket.

      I've tried the following 5 combinations with no success so far:

      1. OR(Root.ServiceRequestUserLifeCycleStatusCode ('ZJ'),Root.ServiceRequestUserLifeCycleStatusCode!=('Z8'))




      5.IF(OR(Root.ServiceRequestUserLifeCycleStatusCode!=TEXT('ZJ'),Root.ServiceRequestUserLifeCycleStatusCode!=TEXT('Z8')), true, false)

      The objective is to have those fields editable only if service request is on either of those status.

      Thank you and best regards.

      Miguel V

      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author


      I hope  your requirement is "When Ticket status is not equal to ZJ or Z8, you want to make some field Read-only".

      Please use the below,

      IF(OR(Root.ServiceRequestUserLifeCycleStatusCode != "ZJ", Root.ServiceRequestUserLifeCycleStatusCode != "Z8"), true, false)

      Apply this rule is Set as Read-Only option.

      Best Regards,

      Abimanyu G.

      Author's profile photo Ricardo Vargas
      Ricardo Vargas

      Hi Abimany G:

      Great post and thank you so much for your help. I haven't been able to test it out because i'm facing an issue (reported to SAP). System is not allowing me to remove rules from KUT fields. In the meantime, i was hoping you can help me with one more question. From the rule at the last question how can I add an exception to the same rule in which Admin users can edit the field at every ticket status?

      Would it be something like this?

      IF(OR(AND(Root.ServiceRequestUserLifeCycleStatusCode != "ZJ", MYUSERROLES()!="ADMIN_SISTEMA"),AND(Root.ServiceRequestUserLifeCycleStatusCode != "Z8", MYUSERROLES()!="ADMIN_SISTEMA")), true, false)

      Again, thank you so much for your help.

      Ricardo V.

      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Hey Ricardo Vargas,

      Your requirement is The field should be read only, when status is "Z8" or "ZJ". But ADMIN can edit that field any time.

      Check this please,

      IF(AND(MYUSERROLES()!="ADMIN_SISTEMA", OR(Root.ServiceRequestUserLifeCycleStatusCode != "ZJ", Root.ServiceRequestUserLifeCycleStatusCode != "Z8")),true, false)


      Abimanyu G.

      Author's profile photo Efrain Pacheco
      Efrain Pacheco

      Few people writes useful blog like this, thank you for sharing

      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Thanks for sharing your thought, Efrain Pacheco.

      Author's profile photo Luis Filipe Pena Borges de Andrade
      Luis Filipe Pena Borges de Andrade

      Thanks for this post! Helped me get what I needed. Good examples and complete!

      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Thanks Luis Filipe Pena Borges de Andrade 👏🏻

      Author's profile photo Kelie Thole
      Kelie Thole


      I love the blog!  Great Job!  I do have a question.  I am trying to write a layout rule that will look at the created on date and time and when the current date and time is <= 2 min make another field read only. 

      For Example:


      Have you done anything like this in the past?  Any help would be greatly appreciated.



      Author's profile photo Kelie Thole
      Kelie Thole

      Hi Great Blog!

      I am trying to write a layout rule that will make a field available if 2 min has past.

      For example:

      A quote is created at 10:00 and I have a process in the background that needs to run before a field can become available.  So at 10:02 or after they can access the field.

      Have you done this before?  If so could you share an example of a rule?



      Author's profile photo Abimanyu G
      Abimanyu G
      Blog Post Author

      Hi Kelie,

      I guess with only the KUT rule we can't achieve this. But I have a workaround. Please find below.

      1. Create a KUT indicator field,

      2. Create a Workflow like below,


      workflow event details


      workflow action details


      workflow field update

      3. Activate the Workflow rule,

      4. Now create a KUT rule in Adaptation Mode like below,

      IF(your_indicator == true, true, false)


      How will it work,

      1. When a quote is created, automatically the above workflow will get triggered after two minutes based on the Created-On date field and it will update your_indicator field to true.

      2. Once the indicator is set to true, by using above KUT adaptation rule, automatically the field will become editable or visible.

      I hope this helps you. Kindly confirm your result.


      Thank you,

      Abimanyu G.

      Author's profile photo MINOT GILLES

      Hello Abimanyu


      Excellent article very detailed but in the rules I do not see the possibility of adding value . The field is not present, is there a configuration before use?



      rule value

      Thank you for your answer



      Author's profile photo MINOT GILLES

      sorry but i saw my mistake. This concerns only the quick access screens




      Author's profile photo Karola Wittkamp
      Karola Wittkamp

      Hello Abimanyu G,

      thank you for the great blog post.

      I have the following question: For a customer, the action for deleting a contact relationship (overview of the contact persons of a customer) should only be displayed if the contact has already become obsolete. Can this be controlled by a rule?

      Thank you and kind regards,