in my Project, there was a requirement to perform similar checks on different Transactions, especially Opportunity and Lead.
As a good programmer I have learnt, not to implement the same code multiple times, use a reuse method instead. That’s why I started using a Reuse Library in C4C. My requirement was that I had to raise an error message, when the check wasn’t successful. As I knew, it is impossible to raise a message from a reuse function, so I asked here on SCN for help.
You can check it here: http://scn.sap.com/thread/3857803
With the provided help, I have achieved my requirements by creating a Reuse Library for performing checks and raise messages (indirectly 😉 )
Here are the steps that I have performed to achieve this:
- Create a Reuse Library (CheckSomething.library)
- Create a Function (CheckField)
- As return Parameter I have checked the Checkbox “CollectionOf” and as Type I use “LANGUAGEINDEPENDENT_LONG_Text”
(I need the possibility to create more than one Message, that’s why I used a collection. If you only need one Message, just leave the Checkbox blank)
- (Optional) depending on your check, you can handover some Parameter. As we want to reuse it in different Transaction, you can handover for example the Value you want to do a check on. I have implemented 2 Parameters that I have to Import.
- Activate the CheckSomething.library, the Function is created automatically. Then you can implement it.
Here is some example coding:
var text_collection : collectionof LANGUAGEINDEPENDENT_LONG_Text;
var text : LANGUAGEINDEPENDENT_LONG_Text;
//Implement the Check on the value
if(<condition = true>)
//Fill the text collection with the needed error messages
- text.content = “<Your Error Message>”;
This is just a part of my code. I have also implemented a loop, to fill my Collection with more Texts. If you don’t have a collection, just return the text.
- Implement a Message in the XBOs (Opportunity.xbo, Lead.xbo, …)
[Extension] businessobject AP.CRM.Global:Opportunity
message MsgFromReuse text “&1”:LANGUAGEINDEPENDENT_LONG_Text;
I am using “&1” to fill the message with any Text I want when raising the message.
- I have implemented the OnSave-Validation (if you want to rise only the Incidents, Implement the AfterModify).
Logic that I have implemented on On-Save was that when the message collection is filled, my check was successful to catch the error in User Inputs. So the Transaction shouldn’t be saved and the message should appear.
var message : LANGUAGEINDEPENDENT_LONG_Text;
var message_Collection : collectionof LANGUAGEINDEPENDENT_LONG_Text;
message_Collection = CheckSomething.Check(<your Attributes>);
return = false;
foreach(var text in message_Collection)
message = text;
raise MsgInvolvedParties.Create(“E”, message);
- After this implementation, perform testing.
I hope this helps someone who has a similar requirement.
Kindly provide your valuable feedback to improve this implementation. 😉
Special thanks to all who helped me to implement this. ➕