Open Closed

Can not use the data received from Dynamic JavaScript API Client Proxies outside the scope #903


User avatar
0
nurul.talukder created
  • ABP Framework version: v3.3.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

I am trying to use Dynamic JavaScript API Client Proxies and use the values to populate the options in a Select dropdown. I am able to get the data but the problem i am facing is that I can not use the data outside the function scope. Inside the Proxies function, the data is available but when I want to use it outside the function then it is showing "undefined".

$typeId = data.items[i].achievementRegister.achievementTypeId;      //selected value from a dropdown list
$achievementRegisterId = data.items[i].achievementRegister.id;
$achievementRegisterName = data.items[i].achievementRegister.fullName;

var code;
achievementTypeService.get($typeId)
                        .then(function (result) {
                            code = result.code;
                            //console.log(code);               // showing the value
                        });
//creating an option for another select
temp = {
                        id: $achievementRegisterId,
                        text: '<span><b>' + code + '</b> ' + $achievementRegisterName + '</span>'          // but not getting the value here
            };
  
  //adding the new option in the Select dropdown
  newOption = new Option(temp.text, temp.id, false, false);
  qualSelect.append(newOption).trigger('change');

Output:

I am not sure what I am doing wrong. I have tried to use the JS type variable ($code) and also declaring local variable (var code). But both of them gives the same problem.

Is there anyway to access the data outside the proxy functions?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    I think you are making a JS exception. var code; is defined and also being used before data is being fetched from achievementTypeService.get($typeId) and that's why it's undefined. this is kinda out of ABP scope but I suggest you to refactor this as below

    var createNewOption = function(newCode){
    //creating an option for another select
    temp = {
                            id: $achievementRegisterId,
                            text: '<span><b>' + newCode + '</b> ' + $achievementRegisterName + '</span>'          // but not getting the value here
                };
      
      //adding the new option in the Select dropdown
      newOption = new Option(temp.text, temp.id, false, false);
      qualSelect.append(newOption).trigger('change');
     
    }
    
    
    achievementTypeService.get($typeId)
                            .then(function (result) {                            
                               createNewOption(result.code);
                              });
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    nurul.talukder created

    Hi Thanks for the response. It is working now. :)

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.