Hi Team,
We are trying to call custom service from Section Schema using ServiceHelper but it is showing and error "ServiceHelper.callService is not a function".
Please see the below screenshot
Please help in order to achieve this.
Many thanks.
Like
Hi Rahul,
Use the approach similar to the below:
define("ContactSectionV2", ["ServiceHelper"], function(ServiceHelper) { return { entitySchemaName: "Contact", details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/, diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/, mixins: {}, methods: { getSectionActions: function(){ var actionMenuItems = this.callParent(arguments); ServiceHelper.callService({ serviceName: "SocialSubscriptionService", methodName: "SubscribeUser", callback: function(response){ console.log("Response from the SocialSubscriptionService in the ContactSectionV2"); console.log(response); } }); return actionMenuItems; } }, }; });
I've received the response properly:
Best regards,
Oscar
Rahul,
Then you've either replaced the section incorrectly or you haven't added ServiceHelper module as a dependency to the replaced section. The error message itself states that ServiceHelper object is either null or undefined. Try also compiling your app. Please debug the logic. If everything is working properly using the code I shared, then it should work in your case.
Best regards,
Oscar
Rahul,
Make sure the top of your section schema looks something like
define("BaseSectionV2", ["ServiceHelper"], function(ServiceHelper) {
Also, if you have multiple dependencies defined in the top, make sure the order of them line up correctly in the list in the brackets ["Thing1", "Thing2"] and in the parentheses (Thing1, Thing2)
If you're unsure, please post what the top of your section schema looks like here.
Ryan
Rahul,
Change that to be the following instead:
define("BaseSectionV2", ["RightUtilities", "MaskHelper", "BaseSectionV2Resources", "ServiceHelper", "css!UsrVirSectionFieldChangeActionMsgContainerStyle"], function(RightUtilities, MaskHelper, Resources, ServiceHelper) {
Basically, switch the "css!" and the "ServiceHelper" in the square brackets.
The order of the items in the square brackets [ ] must match the order of the items in the parentheses ( ). As you had it before, the order didn't match since the css item was before the ServiceHelper. When items are in the square brackets, you're telling the system to "load this thing". When you put a corresponding item in the parentheses, you're telling the system "when you load that thing in the square brackets, give me a reference to it in this variable". Hope that helps.
Ryan