Code in SmartObject method?


Badge +1

Question:

Is it possible to add custom code to a SmartObject method?

 

Example:

I want to write a function which accesses a webservice, retrieving between 1 and n payment terms. Each term has a payment plan (monthly, quarterly and yearly) and a number of periods (ex 24). I want my SmartObject method to return the sum of all these payment terms in months:

 

- Term 1   8 periods (monthly) = 8 x 1 = 8 months

- Term 2   4 periods (quarterly) = 4 x 3 = 12 months

- Term 3   2 periods (yearly) = 2 x 12 = 24 months

- Term 4   2 periods (monthly) = 2 x 1 = 2 months

 

Expected result:

In this example the function would need to return 46 months. (8 + 12 + 24 + 2)


7 replies

Badge +7

At the moment I do not believe you can add custom code to a Smart Object's method.


 


You can create custom code in a service object and call it with a SmO and do your function that way.


 

Badge +7

Good Morning Matt,

 

This is possible...the first web service I created and tested to work with K2 was simple calculations that would return a sum or subtraction of a couple of numbers or fields.

 

First thing you need to make sure is that the Dynamic web service is running on your system.  I had to go into the k2 service broker and enable it.  When the web service is running, you can right click it out of the object tester and point it to any of your web services and it goes in fairly easily.

 

C:Program Files (x86)K2 blackpearlServiceBroker

16108i86C89555EB36476E.png

 

Badge +8

To clarify, both JakeCooley and daerne are correct.  Jake is referencing the ability to have your code live in an assembly on the K2 server, and daerne is referencing the ability to have your code live within a web service outside the K2 environment.  Either approach is valid and available to you as part of a stock K2 installation.  We use both methods in different scenarios in our environment.

Badge +1

Thanks everybody! Have a cookie kudo ^_^

Badge +10

Sorry to hijack this thread but this seems like the perfect pace to ask. When using this service instance type, how are you guys setting the required and not required properties when generating a smartobject out of the web service. It sets all fields as required for me.

 

Thanks in advance.

Badge +8

On top of the "all fields are required" criteria, your workflow will error out if you try to pass an empty string as one of the parameters (even if that is a legitimate use case).

 

We basically have to support NULL values within the methods we are calling.  We then test all parameters for empty before calling the method.  If a parameter is empty, we pass scnull to the SmartObject.  This is some sort of magical (and undocumented) reserved word in K2 that passes NULL to the calling method.

Badge +10

Thanks for your reply. Let me just confirm that I understand this correctly.

 

So you cannot really set required and not required in the actual smartobject method when using a webservice. You just check in the webservice itself ifor null values. Everything is required but if you pass "scnull" then its thinks its null.

 

Now lets say I have a "create" method which takes three parameters. Now lets say I have a form with three input boxes.

I will now map input box one to method parameter input one.

I will map input box two to method parameter input two. 

I will map input box three to method parameter input three.

 

So, my question is if input box one was required and the other two input boxes were optional. How would I pass in scnull to the method if input box two and three are empty.

 

Please let me know if something is not clear.

Thanks

Reply