Open Closed

Unable to locate app service in page/*/index.js #5306


User avatar
0
moinahmed created

I have created a new entity and it's respective page, models, and app service in a separate project and then manually moved every artifact into my project. The entity listing and crud operations were working perfectly fine in the separate project where I actually generated it, however, the issue started arising when I moved all the artifacts into my main project. All looks good, except I cannot locate app service in my entity-page's index.js file. My entity name is agencyCustomer and when I go in index.js file, the code fails at: var agencyCustomerService = window.iosIdentity.pS3.agencyCustomers; The error says iosIdentity.pS3 is undefined or null, while I can see the namespace is there with the app service. I'm unsure about why the error is coming. I have made sure all the code files are moved properly with every change carefully checked, but stuck on the above error. Any idea what could have gone wrong here?

Thanks, Moin


14 Answer(s)
  • User Avatar
    0
    nlachmuthDev created

    Hi,

    i assume you use Asp.Net Core MVC as frontend right? It could be that the namespace is not ready to the exact moment when you try to access it in the js file.

    Would you mind sharing the index.js file so i can have a look?

    Kind Regards Nico

  • User Avatar
    0
    moinahmed created
    $(function () {
        var l = abp.localization.getResource("IosIdentity");
    	
        var agencyCustomerService = window.iosIdentity.pS3.agencyCustomers;
    	
            var lastNpIdId = '';
            var lastNpDisplayNameId = '';
    
            var _lookupModal = new abp.ModalManager({
                viewUrl: abp.appPath + "Shared/LookupModal",
                scriptUrl: "/Pages/Shared/lookupModal.js",
                modalClass: "navigationPropertyLookup"
            });
    
            $('.lookupCleanButton').on('click', '', function () {
                $(this).parent().find('input').val('');
            });
    
            _lookupModal.onClose(function () {
                var modal = $(_lookupModal.getModal());
                $('#' + lastNpIdId).val(modal.find('#CurrentLookupId').val());
                $('#' + lastNpDisplayNameId).val(modal.find('#CurrentLookupDisplayName').val());
            });
    	
        var createModal = new abp.ModalManager({
            viewUrl: abp.appPath + "AgencyCustomers/CreateModal",
            scriptUrl: "/Pages/AgencyCustomers/createModal.js",
            modalClass: "agencyCustomerCreate"
        });
    
    	var editModal = new abp.ModalManager({
            viewUrl: abp.appPath + "AgencyCustomers/EditModal",
            scriptUrl: "/Pages/AgencyCustomers/editModal.js",
            modalClass: "agencyCustomerEdit"
        });
    
    	var getFilter = function() {
            return {
                filterText: $("#FilterText").val(),
                name: $("#NameFilter").val(),
    			brandId: $("#BrandIdFilter").val(),			
    			answerDataUploadOptionId: $("#AnswerDataUploadOptionIdFilter").val(),			
    			subAccountInventoryControlTypeId: $("#SubAccountInventoryControlTypeIdFilter").val(),			
                allowSubAccounts: (function () {
                    var value = $("#AllowSubAccountsFilter").val();
                    if (value === undefined || value === null || value === '') {
                        return '';
                    }
                    return value === 'true';
                })(),
    			organizationUnitId: $("#OrganizationUnitIdFilter").val()
            };
        };
    
        var dataTable = $("#AgencyCustomersTable").DataTable(abp.libs.datatables.normalizeConfiguration({
            processing: true,
            serverSide: true,
            paging: true,
            searching: false,
            scrollX: true,
            autoWidth: true,
            scrollCollapse: true,
            order: [[1, "asc"]],
            ajax: abp.libs.datatables.createAjax(agencyCustomerService.getList, getFilter),
            columnDefs: [
                {
                    rowAction: {
                        items:
                            [
                                {
                                    text: l("Edit"),
                                    visible: abp.auth.isGranted('IosIdentity.AgencyCustomers.Edit'),
                                    action: function (data) {
                                        editModal.open({
                                         id: data.record.agencyCustomer.id
                                         });
                                    }
                                },
                                {
                                    text: l("Delete"),                                
                                    visible: false, // abp.auth.isGranted('IosIdentity.AgencyCustomers.Delete'),
                                    confirmMessage: function () {
                                        return l("DeleteConfirmationMessage");
                                    },
                                    action: function (data) {
                                        return false;
                                        //agencyCustomerService.delete(data.record.agencyCustomer.id)
                                        //    .then(function () {
                                        //        abp.notify.info(l("SuccessfullyDeleted"));
                                        //        dataTable.ajax.reload();
                                        //    });
                                    }
                                }
                            ]
                    }
                },
    			{ data: "agencyCustomer.name" },
    			{ data: "agencyCustomer.brandId" },
                {
                    data: "agencyCustomer.answerDataUploadOptionId",
                    render: function (data) {
                        return l('Enum:UploadOption.' + data);
                    }
                },
                {
                    data: "agencyCustomer.subAccountInventoryControlTypeId",
                    render: function (data) {
                        return l('Enum:ControlType.' + data);
                    }
                },
                {
                    data: "agencyCustomer.allowSubAccounts",
                    render: function (allowSubAccounts) {
                        return allowSubAccounts ? 'Yes' : 'No';
                        //return allowSubAccounts ? '<i class="fa fa-check"></i>' : '<i class="fa fa-times"></i>';
                    }
                },
                {
                    data: "organizationUnit.displayName",
                    defaultContent : ""
                }
            ]
        }));
    
        createModal.onResult(function () {
            dataTable.ajax.reload();
        });
    
        editModal.onResult(function () {
            dataTable.ajax.reload();
        });
    
        $("#NewAgencyCustomerButton").click(function (e) {
            e.preventDefault();
            createModal.open();
        });
    
    	$("#SearchForm").submit(function (e) {
            e.preventDefault();
            dataTable.ajax.reload();
        });
    
        $('#AdvancedFilterSectionToggler').on('click', function (e) {
            $('#AdvancedFilterSection').toggle();
        });
    
        $('#AdvancedFilterSection').on('keypress', function (e) {
            if (e.which === 13) {
                dataTable.ajax.reload();
            }
        });
    
        $('#AdvancedFilterSection select').change(function() {
            dataTable.ajax.reload();
        });
        
        
    });
    
  • User Avatar
    0
    moinahmed created

    Yes, I'm using MVC Razor. When I debug the code and put the breakpoint on var agencyCustomerService = window.iosIdentity.pS3.agencyCustomers; I can see iosIdentity namespace is picked, however, the next part pS3 never realized and throws error.

  • User Avatar
    0
    moinahmed created

    Here's my Application Service:

    using IosIdentity.Shared;
    using Volo.Abp.Identity;
    using System;
    using System.IO;
    using System.Linq;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using System.Linq.Dynamic.Core;
    using Microsoft.AspNetCore.Authorization;
    using Volo.Abp;
    using Volo.Abp.Application.Dtos;
    using Volo.Abp.Application.Services;
    using Volo.Abp.Domain.Repositories;
    using IosIdentity.Permissions;
    using IosIdentity.PS3;
    
    namespace IosIdentity.PS3
    {
    
        [Authorize(IosIdentityPermissions.AgencyCustomers.Default)]
        public class AgencyCustomersAppService : ApplicationService, IAgencyCustomersAppService
        {
    
            private readonly IAgencyCustomerRepository _agencyCustomerRepository;
            private readonly AgencyCustomerManager _agencyCustomerManager;
            private readonly IRepository<OrganizationUnit, Guid> _organizationUnitRepository;
    
            public AgencyCustomersAppService(IAgencyCustomerRepository agencyCustomerRepository, AgencyCustomerManager agencyCustomerManager, IRepository<OrganizationUnit, Guid> organizationUnitRepository)
            {
    
                _agencyCustomerRepository = agencyCustomerRepository;
                _agencyCustomerManager = agencyCustomerManager; _organizationUnitRepository = organizationUnitRepository;
            }
    
            public virtual async Task<PagedResultDto<AgencyCustomerWithNavigationPropertiesDto>> GetListAsync(GetAgencyCustomersInput input)
            {
                var totalCount = await _agencyCustomerRepository.GetCountAsync(input.FilterText, input.Name, input.BrandId, input.AnswerDataUploadOptionId, input.SubAccountInventoryControlTypeId, input.AllowSubAccounts, input.OrganizationUnitId);
                var items = await _agencyCustomerRepository.GetListWithNavigationPropertiesAsync(input.FilterText, input.Name, input.BrandId, input.AnswerDataUploadOptionId, input.SubAccountInventoryControlTypeId, input.AllowSubAccounts, input.OrganizationUnitId, input.Sorting, input.MaxResultCount, input.SkipCount);
    
                return new PagedResultDto<AgencyCustomerWithNavigationPropertiesDto>
                {
                    TotalCount = totalCount,
                    Items = ObjectMapper.Map<List<AgencyCustomerWithNavigationProperties>, List<AgencyCustomerWithNavigationPropertiesDto>>(items)
                };
            }
    
            public virtual async Task<AgencyCustomerWithNavigationPropertiesDto> GetWithNavigationPropertiesAsync(Guid id)
            {
                return ObjectMapper.Map<AgencyCustomerWithNavigationProperties, AgencyCustomerWithNavigationPropertiesDto>
                    (await _agencyCustomerRepository.GetWithNavigationPropertiesAsync(id));
            }
    
            public virtual async Task<AgencyCustomerDto> GetAsync(Guid id)
            {
                return ObjectMapper.Map<AgencyCustomer, AgencyCustomerDto>(await _agencyCustomerRepository.GetAsync(id));
            }
    
            public virtual async Task<PagedResultDto<LookupDto<Guid>>> GetOrganizationUnitLookupAsync(LookupRequestDto input)
            {
                var query = (await _organizationUnitRepository.GetQueryableAsync())
                    .WhereIf(!string.IsNullOrWhiteSpace(input.Filter),
                        x => x.DisplayName != null &&
                             x.DisplayName.Contains(input.Filter));
    
                var lookupData = await query.PageBy(input.SkipCount, input.MaxResultCount).ToDynamicListAsync<OrganizationUnit>();
                var totalCount = query.Count();
                return new PagedResultDto<LookupDto<Guid>>
                {
                    TotalCount = totalCount,
                    Items = ObjectMapper.Map<List<OrganizationUnit>, List<LookupDto<Guid>>>(lookupData)
                };
            }
    
            [Authorize(IosIdentityPermissions.AgencyCustomers.Delete)]
            public virtual async Task DeleteAsync(Guid id)
            {
                await _agencyCustomerRepository.DeleteAsync(id);
            }
    
            [Authorize(IosIdentityPermissions.AgencyCustomers.Create)]
            public virtual async Task<AgencyCustomerDto> CreateAsync(AgencyCustomerCreateDto input)
            {
    
                var agencyCustomer = await _agencyCustomerManager.CreateAsync(
                input.OrganizationUnitId, input.Name, input.AllowSubAccounts, input.BrandId, input.AnswerDataUploadOptionId, input.SubAccountInventoryControlTypeId
                );
    
                return ObjectMapper.Map<AgencyCustomer, AgencyCustomerDto>(agencyCustomer);
            }
    
            [Authorize(IosIdentityPermissions.AgencyCustomers.Edit)]
            public virtual async Task<AgencyCustomerDto> UpdateAsync(Guid id, AgencyCustomerUpdateDto input)
            {
    
                var agencyCustomer = await _agencyCustomerManager.UpdateAsync(
                id,
                input.OrganizationUnitId, input.Name, input.AllowSubAccounts, input.BrandId, input.AnswerDataUploadOptionId, input.SubAccountInventoryControlTypeId, input.ConcurrencyStamp
                );
    
                return ObjectMapper.Map<AgencyCustomer, AgencyCustomerDto>(agencyCustomer);
            }
        }
    }
    
  • User Avatar
    0
    nlachmuthDev created

    Did you update the client proxy js in the target project? Seems to me that the application you copied to does not have the js client for that particular app service.

  • User Avatar
    0
    moinahmed created

    how to do that, can you share the steps?

  • User Avatar
    0
    nlachmuthDev created

    Sure.

    Here is the whole documentation for the static js proxies: https://docs.abp.io/en/abp/latest/UI/AspNetCore/Static-JavaScript-Proxies

    so updating would be something like abp generate-proxy -t js -u <yoururl>

    this will generate the js file for the proxies. there should be already another file in your target project. that needs to be overriden by the new file.

    if you use dynamic proxies please let me now. then most properly the app service is not added as auto controller in your target project and so that would explain why the app service is missing in js.

  • User Avatar
    0
    moinahmed created

    How can I make it part of build process?

  • User Avatar
    0
    moinahmed created

    It seems we are using Dynamic proxy, but for some reason it is not being generated; any idea what could be the reason?

  • User Avatar
    0
    moinahmed created

    for some reason the controllers were not auto generated; any idea what could be wrong?

  • User Avatar
    0
    moinahmed created
    Configure<AbpAspNetCoreMvcOptions>(options =>
    {
        options.ConventionalControllers.Create(typeof(IosIdentityApplicationModule).Assembly);
    });
    

    Adding above lines made it working, but for some reason all the filters of the GET listing call have become mandatory. Getting the following error:

    {
      "error": {
        "code": null,
        "message": "Your request is not valid!",
        "details": "The following errors were detected during validation.\r\n - The Name field is required.\r\n - The FilterText field is required.\r\n",
        "data": {},
        "validationErrors": [
          {
            "message": "The Name field is required.",
            "members": [
              "name"
            ]
          },
          {
            "message": "The FilterText field is required.",
            "members": [
              "filterText"
            ]
          }
        ]
      }
    }
    
  • User Avatar
    0
    nlachmuthDev created

    you need to disable the nullable feature for your application.contracts project or make the string props nullable.

  • User Avatar
    0
    moinahmed created

    I tried to disable the feature but it didn't work

  • User Avatar
    0
    nlachmuthDev created

    how did you disable it?

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11