How to set values from API into segment ?!

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Hi,

I've tried too many time to fill the returned data into segment, but it doesn't work!

*Returned Data from API:

{

"Category": [

{

"name": "Gift Ideas"

},

{

"name": "TV & Home Theater"

},

{

"name": "TVs"

},

{

"name": "All Flat-Screen TVs"

},

{

"name": "TV/DVD Combos"

},

{

"name": "Blu-ray & DVD Players"

},

{

"name": "Blu-ray Players"

},

{

"name": "DVD Players"

},

{

"name": "Digital TV Tuners & Converters"

},

{

"name": "TV & Internet Service Providers"

}

],

"opstatus": 0,

"httpStatusCode": 200

}

My Code:

function operationSuccess(res){

var response = res.Category;

this.view.SegCategoryList.widgetDataMap={lblname :"name"};

CategoryList = [];

for (var i=0; i < response.length; i++){

dummyArray={};

dummyArray.name=response[i].name;

CategoryList.push(dummyArray);

}

this.view.SegCategoryList.setData(CategoryList);

}

Console Error:

Uncaught TypeError: Cannot set property 'widgetDataMap' of undefined

Uncaught TypeError: depMaps.slice is not a function

Is there any solution for this issue ?!

@Edwvwd Dyew​

Please find the source code from below which can help you in resolving your issue, it will resolve you first error (Uncaught TypeError: Cannot set property 'widgetDataMap' of undefined) and regarding your second error (Uncaught TypeError: depMaps.slice is not a function) can you share some more info about it, as i am unable to see the depMaps array from which you are trying to get the selected element or elements.

For more information about slice method please use the below link.

Link: https://www.w3schools.com/jsref/jsref_slice_array.asp

Tested on Oneplus 5T

IDE: KVE 8.1.19

Regards

Hi @Nicholvs Hughes​

Thanks for Helping,

===========================================

I will show you my steps:

1- In my Controller:

GetValue:function(){

//"KNYMobileFabric" is the current instance of the Kony Fabric auto initialized by Visualizer

serviceName = "BestBuyProducts";

integrationObj = KNYMobileFabric.getIntegrationService(serviceName);

operationName = "CategoryList";

data= {};

headers= {};

integrationObj.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);

function operationSuccess(res){

if (res !== null && res.opstatus === 0) {

var response = res.Category;

if (response !== null && response.length > 0) {

CategoryList = [];

for (var i in response) {

var dummyArray = {

name: response[i].name,

};

CategoryList.push(dummyArray);

}

this.view.SegCategoryList.widgetDataMap={lblname :"name"};

this.view.SegCategoryList.setData(CategoryList);

}

}

}

function operationFailure(res){

//code for failure call back

}

}

2- In mainForm:

I've clicked on Action tab > preShow option > invoke function > select GetValue

===========================================

Is there any mistakes on the above steps ?!

Hi,

Can you please try using following code

function operationSuccess(res){

if (res !== null && res.opstatus === 0) {

var response = res.Category;

if (response !== null && response.length > 0) {

CategoryList = [];

for (var i in response) {

var dummyArray = {

name: response[i].name,

};

CategoryList.push(dummyArray);

}

this.view.SegCategoryList.widgetDataMap={lblname :"name"};

this.view.SegCategoryList.setData(CategoryList);

}

}

}

Hello,

Unfortunately, doesn't work! i have the same error.

===========================================

I will show you my steps:

1- In my Controller:

GetValue:function(){

//"KNYMobileFabric" is the current instance of the Kony Fabric auto initialized by Visualizer

serviceName = "BestBuyProducts";

integrationObj = KNYMobileFabric.getIntegrationService(serviceName);

operationName = "CategoryList";

data= {};

headers= {};

integrationObj.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);

function operationSuccess(res){

if (res !== null && res.opstatus === 0) {

var response = res.Category;

if (response !== null && response.length > 0) {

CategoryList = [];

for (var i in response) {

var dummyArray = {

name: response[i].name,

};

CategoryList.push(dummyArray);

}

this.view.SegCategoryList.widgetDataMap={lblname :"name"};

this.view.SegCategoryList.setData(CategoryList);

}

}

}

function operationFailure(res){

//code for failure call back

}

}

2- In mainForm:

I've clicked on Action tab > preShow option > invoke function > select GetValue

===========================================

Is there any mistakes on the above steps ?!

@Edwvwd Dyew​

The error may be due to "this.view" not referring to the the following form controller.

Here the context is changed.

This may be due to when you invoke "this.view" in some callback function related to ffi/any other context switching scenarios.

Try the following solution:

Before going to the callback function

save the context to some variable and then use that saved context

Example Scenario where this doesn't work:

define({

myfunction:function(){

this.view.widgetiD.property="" //Here this directly points to form controller.it works.

let self=this; //Assign it .

object.callbackfromffi(function(params)){

self.view.widgetiD.property="" //As "this.view" doesn't work here because this refers to ffi context callback here. So using self here.

});

this.view.widgetiD.property="" //Here this directly points to form controller.it works.

},

});

You can do JavaScript Debugging and can check the "this" object.it should point to Form controller.

"this.Name" should give you the associated form controller name.Otherwise you may get this error:

Uncaught TypeError: depMaps.slice is not a function

can you explain this i am unable to undersatnd.. I too have same error ..this.view