Question

Custom Broker - Can we pass a view or a form as an input to the broker method?

  • 7 October 2020
  • 8 replies
  • 134 views

Badge +2

Hi,

I am trying to build a service broker library which is going to parse a REST api json response and extract text “values” (let say). 

Using a smartobject (generated by another custom broker), let say user creates a view or a form in designer. 

I need to implement a method in my new library which can take this view or form and go through its controls(textboxes) and assign “values” to the controls.

Can anyone please guide me how to provide a view as an input to a method and then assign values to the controls? 

Thanks


8 replies

Userlevel 1
Badge +4

1.create REST service instance (out-of-the-box) for REST API endpoint.

2.create smartobject for available api, add new method on this smartobject to deserialize to array json string, it will return you properties and value.

  1. call this method on smartform/view to populate controls.
Badge +2

Hi @YUDI2 ,

 

Thanks for the reply.

I believe my question wasn't very clear, sorry about that. Deserializing the JSON response is fine , I already have REST endpoint which I am using in my broker.

The problem is - When user creates a view, is there a way that custom broker can parse this view, get all the textbox controls and assign or map those controls with the deserialized “values”. All the mapping logic will be inside the broker.

User doesn’t have to configure the rule in the view for the mapping part(which is usually done in a normal scenario) . User should just be able to call the broker method inside a button click rule.

So user might just need to do a button click , which will execute my broker method and do the mapping as I mentioned above. User will be able to see all the “values” inside those textbox controls.

What are the possible ways to implement such method , can we pass the whole view or textbox control names to the broker as an input ?

I am not sure if this is going to be the right approach but currently that is the way I think the solution might work. 

It would be great to know if view controls can be passed as an input to the broker method.

Thanks

Userlevel 1
Badge +4

as smartobject is middle layer, I do not think that will be possible but there is a feature AutoMap which help you to map between smartobject fields and view/smartform controls automatically in design time as long as your view/smartform bound to your smartobject. so you do not need to manually map it one by one.

 

to map the smartobject fields to view on fly on runtime, I’m interesting to know if can be done.

 

Hope it helps.

Badge +2

Hi @YUDI2 ,

Yea the AutoMap works if your smartform is linked to the smartobject which has all the values you want to mapped.

But in my case the smartform will be from a different smartobject (created via a custom broker, A, let say) and the new smartobject (I am trying to implement now ) will be different (via another custom broker , B, )which will have the deserialized values, which in turn should be mapped to the smartform textbox controls via Button Click/smartobject method execution. 

I am not getting any help reference to do this. Sigh! But thanks for your suggestions, I will keep searching.

Userlevel 1
Badge +4

Hi @YUDI2 ,

Yea the AutoMap works if your smartform is linked to the smartobject which has all the values you want to mapped.

But in my case the smartform will be from a different smartobject (created via a custom broker, A, let say) and the new smartobject (I am trying to implement now ) will be different (via another custom broker , B, )which will have the deserialized values, which in turn should be mapped to the smartform textbox controls via Button Click/smartobject method execution. 

I am not getting any help reference to do this. Sigh! But thanks for your suggestions, I will keep searching.

What I think of is, on your smartobject B, you create a new method to wrap the existing method.  This new wrapping method’s properties and data type should exactly the same as smartobject A (the smartobject bound the view/form), you need to do mapping or association on smartobject level.  

if this works, then you can use “automap” to save your times from manual mapping on the smartform/view level manually

 

note : you can edit/customize the generated smartobject 

https://help.k2.com/onlinehelp/k2five/userguide/5.3/default.htm#Create/SmartObjects/CompositeSmartObjects.htm

 

https://help.k2.com/onlinehelp/k2five/userguide/5.3/default.htm#How-Tos/SmartObject-Composite/SmartObjectBasicComposite.htm

Badge +2

Yes, I agree this is one of the option.

But the project requirement is to get done via broker without creating any composite smartobjects in K2 designer. 

Userlevel 1
Badge +4

Yes, I agree this is one of the option.

But the project requirement is to get done via broker without creating any composite smartobjects in K2 designer. 

 

reference :

https://community.k2.com/how-to-videos-164/complex-types-method-chaining-115665

Badge +2

Yes, I followed this method chaining when I used K2 designer without any broker . Now its like doing everything inside a broker library with minimal rule config in views or without any composite smartobjects. 

More of an automated structure.

Reply