I am not getting values in Client controller properly

Priya75
Tera Contributor

 

 

 

 

//server script

else if (input.action == 'impHostingloc') {
var hostingLocation=input.name;
data.cloudServiceProvideList =[]:
var cloudService=(};
if(hostingLocation=="Public"){
var cloudPro = new GlideRecord('sn_capi_provider');
cloudPro.addQuery ("u_cloud_service_provider_type", hostingLocation);
cloudPro.query();
while (cloudPro.next)) {
//gs. info("inside while"+input.name);
cloudService.label=cloudPro.getValue('name');
cloudService.value=cloudPro.sys_id.toStringO;
data.cloudServiceProvideList.push(cloudService);
}
}
else if(hostingLocation=="Private"){
var cloudProdl = new GlideRecord("sn_capi_provider"):
cloudProd1. addQuery ("U_cloud_service_provider_type", hostingLocation)
cloudPro1.query();
while(cloudProdl.next()){
gs. info("inside while"+input, name); 
cloudService.label=cloudProd1,getValue('name');
cloudService.value-cloudProd1.sys_id.toString();
data.cloudServiceProvideList.push(cloudService);
}

else if (input.action == 'getServiceName') {
var ids=input.ids;
data. name= [];
var gr1=new GlideRecord("sn_capi_provider") gr1. addQuery('sys_id', 'IN',ids);
gr1. query);
while (grl.next )
date.name. push(gr1.getValue('name '));
gs. info ("data"+data. name) ;
);



//client Controller

c.cloudService=[];
c.getHostLoc = function() {
var hostingLoc=c.hostloc.displayValue;
console. log("hostinglocation"+c.hostloc.displayValue);
if(hostingLoc==""){
c.cloudservprov='';
}
this.server.get({
action: "impHostingloc" ,
name: hostingLoc,
//listservice: selectedcloud
}).then (function(response) {
c.cloudservprovlist= response.data.cloudServiceProvidelist;
console.log("1891"+c.cloudservprovlist);
}


c.updateSelected =function (){
var selectedCloudService=c.cloudservprov;
console.log("response"+selectedCloudService);
if(selectedCloudService && selectedCloudService. length›0)(
this.server.get ({
action: "getServiceName",
 ids: selectedCloudService
}).then (function(response){
c.cloudService=response.data.name.join ',');
console.log("response"+c.cloudService);

}

//HTML
<sn-choice-list sn-model="c.cloudservprov" table="sn_capi_provider" display-field="name" value-fied='sys_id'
sn-items=c.cloudservprovList" multiple="true" on-change="c.updateSelected()"</sn-choice-list >

 

 

 

 

i am trying to get the values selected by the user , but in the console i am not getting all the values for eg:- first value is skipped first time and then it appears second time , so if i select 4 values only 3 are getting updated

var selectedCloudService=c.cloudservprov;
console.log("response"+selectedCloudService);

6 REPLIES 6

Weird
Mega Sage

 

 

Proof read the script for typos and try again as those can break it completely and prevent you from getting the results you expect.

I've marked a few as comments for you. There were many on this. Generally I'd recommend making sure you write easy to remember variable names and double check for typos. Avoid using similar names on two places. For example I wouldn't write cloudProv and cloudProvList (expecially in lower case) as those can accidentally get mixed while coding.  The code editor should alert you for missing characters. Your code also looks like it's just mixing the code of multiple people since you're not writing in a single coherent format. Proof read this a few times (I might have missed quite a few typos as well) and then try the code editors formatting tool to see how it would format the code. Also consider just using "" or '' instead of mixing them. The very first else if on the code already keeps jumping from one to another style.

else if (input.action == 'impHostingloc') {
var hostingLocation=input.name;
data.cloudServiceProvideList =[]: // : instead of ;
var cloudService=(}; // ( and } mixed. Also you might want to move this inside the while loop.
if(hostingLocation=="Public"){
var cloudPro = new GlideRecord('sn_capi_provider');
cloudPro.addQuery ("u_cloud_service_provider_type", hostingLocation);
cloudPro.query();
while (cloudPro.next)) { //Missing starting ( on next
//gs. info("inside while"+input.name);
cloudService.label=cloudPro.getValue('name');
cloudService.value=cloudPro.sys_id.toStringO;
data.cloudServiceProvideList.push(cloudService);
}
}
else if(hostingLocation=="Private"){
var cloudProdl = new GlideRecord("sn_capi_provider"): //cloudProdl instead of cloudProd1
cloudProd1. addQuery ("U_cloud_service_provider_type", hostingLocation) //Capital U and missing ;
cloudPro1.query();
while(cloudProdl.next()){ // again cloudProd1 should be used here? Also consider moving the var cloudService here as well.
gs. info("inside while"+input, name); 
cloudService.label=cloudProd1,getValue('name'); // comma instead of a dot.
cloudService.value-cloudProd1.sys_id.toString(); // - instead of a =
data.cloudServiceProvideList.push(cloudService);
}

else if (input.action == 'getServiceName') {
var ids=input.ids;
data. name= [];
var gr1=new GlideRecord("sn_capi_provider") gr1. addQuery('sys_id', 'IN',ids); //no ; after GlideRecord.
gr1. query); //Missing starting (
while (grl.next ) //grl instead of gr1
date.name. push(gr1.getValue('name ')); //date instead of data
gs. info ("data"+data. name) ;
);



//client Controller

c.cloudService=[];
c.getHostLoc = function() {
var hostingLoc=c.hostloc.displayValue;
console. log("hostinglocation"+c.hostloc.displayValue);
if(hostingLoc==""){
c.cloudservprov='';
}
this.server.get({
action: "impHostingloc" ,
name: hostingLoc,
//listservice: selectedcloud
}).then (function(response) {
c.cloudservprovlist= response.data.cloudServiceProvidelist; //On server this was cloudServiceProvideList
//Note the uppercase List
console.log("1891"+c.cloudservprovlist);
}


c.updateSelected =function (){
var selectedCloudService=c.cloudservprov;
console.log("response"+selectedCloudService);
if(selectedCloudService && selectedCloudService. length›0)(
this.server.get ({
action: "getServiceName",
 ids: selectedCloudService
}).then (function(response){
c.cloudService=response.data.name.join ','); //.join(',') missing (
console.log("response"+c.cloudService);

}

//HTML
<sn-choice-list sn-model="c.cloudservprov" table="sn_capi_provider" display-field="name" value-fied='sys_id'
sn-items=c.cloudservprovList" multiple="true" on-change="c.updateSelected()"</sn-choice-list >

.
 

Priya75
Tera Contributor

that is a typo here, i am getting values. But not all

What values? Did you fix all the typos and try again? Most of the typos should be the type that break your script so it stops running. Even if it ran it would stop looping and return just one thing.

 

Try running part of your server script on background script. You'd have to create custom data and input objects for it to work like the widget, but you'd be able to see when the script actually runs through.

 

To add yo have a while loop that won't run more than once if at all. Then your other query

 

var cloudProdl = new GlideRecord("sn_capi_provider"): //cloudProdl instead of cloudProd1

cloudProd1. addQuery ("U_cloud_service_provider_type", hostingLocation) //Capital U and missing ;

cloudPro1.query();

You mix multiple typos here.

cloudPro1

cloudProd1

cloudProdl

No way that's going to work as expected.

Priya75
Tera Contributor

I have not copied the original code; it has some typos here, but I am getting values as I already mentioned. The problem that I am getting is that all values are not getting in the console. If user selects 3 values 2 are getting displayed.