cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a code sample for a custom action that can accept parameters?

Former Member
0 Kudos

I looked through the help documentation and couldn't find any reference/example to define a custom action that accepts parameters.

I want to create a custom action FooBar(), which can accept parameters such as ID, Type

I would assume that when I call the action it would be CustomBO.FooBar(12, "AB");

The custom action definition would then use 12 and "AB" parameters as variables in the custom action script.

There are no examples of calling an action with parameters and defining an action with parameters , so does this mean this is not possible or it is, but not documented?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

You can try something funky with Reusable libraries though and let us know the results if you need it so badly.

Consider the primary key of your CustomBO as UUID.

Call ReUseLib.FooBar(UUID,12, "AB") and "Retrieve" your customBO's instance with UUID in the library's action FooBar and perform your operations there. I am going ahead and taking a wild guess that as this is happening in the same session, user whoever is performing actions should not get any lock messages.

But, I believe SAP would be providing this feature very soon as this is something being asked from long time.

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Srivatsava,

I can at least assure that it is the same session.

Bye,

   Horst

Former Member
0 Kudos

Hi Rei,

That is possible, use a Reuse Library and there you can create functions with parameters.

You can define an Import (with parameters) or a Return (returns something) method.

In order to call in ABSL, you use YourReuseLibrary.YourMethod(Params here).

There are a few restrictions with Reuse Libraries as mentioned by Daniel.

Best regards,

Fernando Giroleti

SAP Cloud Service Center AMEA

vinodkumar_kommineni
Active Contributor
0 Kudos

Hi Fernando

I think Rei was looking at creating actions with parameters within a BO's node. Is that possible ?

Regards

Vinod

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Rei, Vinod,

Sorry, but it is not possible to have actions at a Custom BO with parameters.

Bye,

     Horst

Former Member
0 Kudos

As far as i've seen, this isn't possible, at least as of 1308. I haven't really read through the 1311 documentation, though.

There are ways around it. You can use elements (regular or transient) and use these within the Business Object action.

Then within CustomBO.FooBar() (without parameters) you can use these elements.

Alternately, you can make a Reuse Library function, which DOES allow for parameters to be passed in - however, the Reuse Library functions don't let you raise messages as part of the function. I've used it in a few circumstances where i'd pass parameters in to a reuse function that would return a Code data type, and based on the code returned i'd take further action.

Generally i'd do this if i need to have validations in multiple locations within a SAP Business Object.

What does this requirement stem from? That'd help use recommend the best alternative.

Former Member
0 Kudos

Hello Dan,

Is there a way to access BO elements within the BO custom action without passing as parameters?

Reusable library with input as BO UUID would not work for me as I have not saved the BO element values before executing the BO action.

Regards,

Sangeeta

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sangeeta,

It is not possible to pass parameters in an action, but the action runs instance-based.

That means the elements of this node instance can be accessed.

HTH,

   Horst

Former Member
0 Kudos

Hello Horst,

My action is on the Root node, however I am unable to access the root node instance elements using 'this.XX'.

Could you let me know how can I access ?

Regards,

Sangeeta

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sangeeta,

Can you tell us how your action is defined? As well in the BODL as in the ABSL.

Thanks,

     Horst

Former Member
0 Kudos

Hello Horst,

The action is define under Root as given below:

Business Object SPR{

[Label("Customer")] element AccountPartyID : PartyID ;

action Calculation;

}

action absl code

var Request: Library::SPRCalcEWSI.SI_Calc_Send.Request;

Request.MT_Calc_Send.Customer = this.AccountPartyID;

this.AccountPartyID cannot be accessed.

Regards,

Sangeeta

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sangeeta,

Okay, that looks fine.

How do call this action?

From the UI you have to ensure that the action is bound to a instance of your Custom BO SPR.

Bye,

   Horst

Former Member
0 Kudos

Hello Horst,

I could solve the issue. While creating script file, I had clicked on 'Mass enable', which is wrong. On removing mass enable, I could access the root node elements.

Regards,

Sangeeta

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sangeeta,

With "Mass Enabled" the "this" is a collection and not a singel instance.

But you found it by yourself.

Bye,

    Horst