Product Information
Comparing previous and current values for custom MDF in Successfactors
Introduction
In this Blog, I am going to demonstrate a use case where we need to create rules based on field changes of an MDF object. Reason for the blog: Most of the customers/partners are unaware of this functionality and find challenges to implement use cases in MDF which requires field comparison for custom applications. This is similar to the Model concept for HRIS Objects like Job information, Compensation Information where we have the capability to check previous value and current values of fields and decide on next steps in rules.
Typical examples include:
- Based on field value changes, you would want to trigger a specific workflow
- You would like to set specific event reasons in Position Object based on different combination of field changes
- You would like to raise validation messages based on field changes
Initially, this concept was delivered for Position but now this can be used for a custom MDF as well. The concept used by MDF is a parameter called “OriginalValues”. The OriginalValues is a replica of the base object (any custom MDF or Position object). The OriginalValues parameterized object stores the previous values for all attributes of the base object.
I will demonstrate this by using a simple custom MDF. I have a custom MDF named “Employee Stock”. An employee can be granted a stock value. But if an admin/user tries to change the value or rather give a jump of more than 200, then a validation error needs to be thrown. For example, lets say we have granted 100 shares to an employee. Now if we try to change that value to greater than 300, it should throw an error. If the difference is less than 200 it should allow us to save
Configuration of Custom MDF & Rules
The custom MDF has three fields:
External code: User
Effective Start Date: Date
Stock Value: Decimal
Create a rule as below. Add an additional parameter named “OriginalValues” with base object as Employee Stock
LATEST UPDATE
You don’t need to add these parameters manually now. Create the rule using the MDF rule scenario (not “Basic”)! With that, the necessary parameters (e.g. previous value, original value…) are correctly added to the rule and you do not need to take care of the correct spelling or code. This prevents issues
Attach the rule at the onSave hook of Employee Stock Object Definition
Working
An Employee is granted Stock value of 100 initially as shown below
Scenario 1:
Manager/Admin tries to provide a jump of 250 by changing the value to 350
We see an error message thrown. This basically compares 100 with 350 and sees that jump is more than 200 as per rule config. Hence the message
Scenario 2:
Manager/Admin tries to provide a jump of 150 by changing the value to 250
We see that data is saved successfully as the difference between previous (original) value and the current value is less than 200 as per our rule
The above is a simple example to demonstrate this feature for custom MDF. You can extend this to any specific use case which involves field comparison across MDFs
Hi Neelesh!
Excellent Article !!!It adds awareness about a new dimension to the functionality of MDF objects.just a clarification the functionality works even if MDF Version History is selected as "NO" !!!
Thanks Rajesh for the feedback :). Yes it works even if History is "No"
Hi Neelesh,
Thank you for sharing this information. Its very helpful, solves lot of issues.
Thanks once again.
Thanks Neelam 🙂
Hi Neelesh,
Thanks for the documentation. I have used your suggestion to validate the old value. My business rule is giving the below error. What should be the 'code' field used in Parameter section of rule definition?
Rule "XXXXXXXXX" execution failed with error "Rule execution context is null, either because OriginalValue is not a valid object or OriginalValue has no corresponding instance"
Regards
Shyam
Hi Shyam,
The code field for rule parameter is "OriginalValues" .
Thanks
Neelesh
Can you please help with the same logic using Canvas Report to compare previous and current value?
Unfortunately, I am not a reporting expert..So I cannot comment on it
Hi Neelesh Kamath Thanks for share it!
Does it work for child data? I need to validate if and what child row was modified. Is it also possible to compare the entire child object or must be compared field by field?
Thanks
Thanks . Yes ideally it should work for all MDF objects. For child , you need to create a rule with base object as child and attach it to child object definition. I have not personally tried it on Child objects. But you can try it
Hi, thanks for you reply.
It shows an error in the execution log: The expression 'OriginalValues' could not be evaluated completely as the property 'OriginalValues' is found to be NULL at 'OriginalValues'. Evaluation result is NULL.
It says that is null but it has 3 rows as child object.
You can refer to the link to create the new MDF based rule scenario validation https://help.sap.com/viewer/e4a4ce68589841709a8202928c23803a/2105/en-US/614e2d0010eb483bbbfd951df009196d.html
If it does not work for child, kindly report an incident to SAP..
BTW I was able to do some alternative using rule based on parent MDF and then checking child MDF records..you might have to select the where clause corretly..This works for me
hello Neelesh,
How will it work for other data types than decimal, like for field with string/picklist/ date
Thanks In advance
This is very helpful. Thanks
Very helpful blog, Neelesh!
Just to increase the awareness (it was already mentioned in a discussion between Neelesh Kamath Shyam Valakatte, and Renan Vasconcelos Girard , but might be overlooked:
Create the rule using the MDF rule scenario (not "Basic")! With that, the necessary parameters (e.g. previous value, original value...) are correctly added to the rule and you do not need to take care of the correct spelling or code. This prevents issues. For such a rule, the purpose would be "evaluate", as this can be assigned onSave as well as raise message is allowed.
Hope this helps!
BR, Sylvia
Thanks, Sylvia
You are right.Now we have those parameters instilled in the MDF rule scenario
My blog was created way back in the past in 2018 when these rule scenarios did not exist and this was one of the ways to do the comparison and you had to add these parameters manually
I will also update my blog at the end that these parameters exist directly in the rule scenario now
Best Regards
Neelesh