With the 2102 release of SAP Sales Cloud / Service Cloud (aka Cloud for Customer) solution, SAP released a new feature “Default Values using Rules” for general availability.
The release briefing notes are also promising!
“Customers can now use rules to set the default value for any field” and “Applicable only in quick create screens”
(all credits to release briefing notes: SAP Cloud for Customer 2102 Release Briefings )
Awesome! I was excited! No more SDK code required to default some fields based on other fields’ values in Quick Create screens!
Even better “Default Value Rule will override any other logic in place Ex: will override CLR, Extension Scenario, SDK Script Determination, Application logic etc”.
Exactly what I just need right now! What an amazing coincidence!
However, when I created a value rule (now there are two types of rules: property and value rules) and went to assign it to the field I was scratching my head.
But they said ‘quick create screen’, right?…
– Yes, I’m right in quick create screen…
‘use rules’, they said?..
– Yes, I have one beaut…
‘Any field’, they said?..
– Aye! Any!
I found a bug, I thought! And hurried to report an incident. I really wanted to use this feature. I was having the exact use case for it. So let’s get it fixed and get it done!
…The incident came back saying: everything works as designed. It’s not any field. Here you go with the list of restrictions:
Cannot be applied to Object Value Selector Fields (Ex: Account Object Field) and Multi Value Fields.
And to make things clear what ‘any field’ from release briefing notes actually means a new KBA was issued after my incident: 3026159 – Default Value Using Rules Current Limitations
Almost forgot, in the incident, there was a usual suggestion to go and log feature request at Influence SAP. Yeah nah for sure!
And now I’m going to share a way to apply the default value rule even to fields mentioned in the KBA as limitations. Just a bit of disclaimer: I’m describing my own experience at the time of writing this blog post. If you want to repeat these steps, you’re more than welcome. But you’re on your own, no strings attached.
My scenario is simple: in the quick create screen of the ticket, I need to populate Service Category (OVS field) based on the customer selected.
1. Create a value rule. We’ll need it.
2. Now open the Developer tools of your preferred browser and find AddValueChangeContentController.js. Either search for it or, at the moment of writing this blog post, it sits at https://c4cstatic.hana.ondemand.com/resourcesvc/<some_version_string>/SAP_UI/HTML5/resources/sap/client/flex/designtime/changecontent/addValueChange/AddValueChangeContentController.js in the Resources in Dev Tools. Do a pretty print to see the code a bit more readable.
3. Find _isControlRestricted function. Before the return statement set a breakpoint within it.
4. Select the field you want (but can’t) assign the value rule. Use the right-click on the field, for example, and then one step back to get to its properties. The debugger will stop at the breakpoint.
5. Clear the r variable using the console. r =  would do.
6. Then continue execution.
Voilà. ‘Set Default Value’ appears now in OVS field’s properties.
7. Now we need to select the rule we previously created.
The debugger will stop again at our breakpoint. It is the roundtrip after we selected the rule. Clear the r variable again to see that the rule is in the property now.
8. Apply your adaptation changes by ending the adaptation.
And check the result.