I am unable to input just one numerical value into my function

I am encountering an issue with my function that calls another function. The problem arises when inputting single numbers in the prompt; I have to append a letter like (a1, a2, a3) for it to function correctly.

The function "PrintSelectedToPDF" works smoothly without any errors when running it through a loop in my database instead of using user input prompts. However, I keep getting a "too many requests" error after generating 5 or 6 PDFs, which led me to this temporary "solution." Ideally, I would prefer to use only single numbers in my spreadsheet.

My attempt:

insert unique text generated here

Answer №1

It appears that the issue arises when creating the 'selectedInvoices' variable, as the map function generates an array of strings while the database sheet values are integers. You can try utilizing the following code snippet:

function promptUserToChooseInvoices(data) {
  // Prompt user to input invoice numbers separated by commas
  var selectedInvoices = [];
  var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Select Invoices to Print', 'Please enter invoice numbers separated by commas:', ui.ButtonSet.OK_CANCEL);

  if (response.getSelectedButton() === ui.Button.OK) {
    var input = response.getResponseText().trim();
    selectedInvoices = input.split(',').map(function(value) {
      return parseInt(value.trim()); // Updated line
    });
 
    // Call the PrintSelectedToPDF() function with the selectedInvoices array
    PrintSelectedToPDF(selectedInvoices);
 }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I effectively assign model data to a service property in an AngularJS controller?

I have established a service to facilitate the sharing of data/state across multiple controllers. One of the controllers updates certain properties within the service using scope data through a save function. The updated data is then accessed by other cont ...

Node.js not resetting array properly

I have successfully set up a Node+Express API that is working smoothly, but I am facing an issue with returning responses for complex queries. The problem lies in the fact that the variable where I store the response data is not being reset between differe ...

Display a sneak peek on a separate tab

I have an editor on my website where users can input and edit their own HTML code. Instead of saving this to a database, I want to display the current user's HTML code in a new window using JavaScript. How can I achieve this without storing the code p ...

I've been stuck on this for the past hour, trying to figure out why /js/bootstrap.min.js can't be located

I'm having an issue with the code in base.html while trying to create a bootstrap starter template. I copied it from bootstrap but when I run it, I get an error related to /js/bootstrap.min.js. Can someone help me figure out what's wrong? Thank y ...

The Vue v-for directive encountered an unrecognized property during rendering

Trying to grasp the concept of v-for in Vue JS, especially since I am a newcomer to this framework. Since I am utilizing Django, custom delimiters are necessary. I have a script example that appends a list of objects to a data property: var app = new Vue( ...

Sending an Ajax request following validation with jQuery

After successfully validating a form, I attempt to make an ajax request. Strangely, if I remove the , after url: 'loginprivate.php', the PHP code functions properly but the validation does not. On the other hand, if I add the ,, the validation wo ...

Having trouble getting my JavaScript code to function properly on Firefox browser

I have created a script where the cursor automatically moves to the next form field once it reaches its maximum length, in this case 1. Here is the JavaScript code: window.onload=function(){ var container = document.getElementsByClassName("container")[0] ...

Encountering issues while establishing a connection to SQL Server through Node.js

I've developed a Node.js application to interact with SQL Server. Here's the code snippet: app.get('/SalesStatistics', function (req, res) { var Connection = require('tedious').Connection; // configuration for the databas ...

What is the best way to dynamically load a personalized JavaScript file for individual users depending on their PHP login credentials?

Currently, I am conducting a web-based experiment in which students log into a website to take practice tests for a class. Initially, the students land on a login page that includes the following code: include_once("core/config.php"); include_once("core/ ...

Ensuring Consistent Data in Web Forms When Editing a User's "Points" Field

In the process of creating a booking system, I am faced with an issue regarding how points are allocated to users. An admin can assign points to a user through a form, which the user then uses when booking a slot. The problem arises when the admin opens th ...

Oops! There seems to be an issue with an invalid character in the literal true value while making a POST request to the API with JSON data. The expected character should be

Can anyone help me solve an issue I am facing while trying to use the POST method to insert data using JSON in JS code? When I attempt the transformation, I receive an error message stating: "ERROR: invalid character ' ' in literal true (e ...

Creating a textured path using Threejs

Having trouble drawing a path in my 3D world, as the line class is not helpful. Can anyone offer assistance? See this image I've updated my question I want to draw a path and fill it with texture. var SUBDIVISIONS = 20; geometry = new THREE.Geo ...

Retrieving the initial item from a Response.Json() object

i have a this code: fetch("https://rickandmortyapi.com/api/character/?name=Rick") .then((response) => { response.json().then((data) => { console.log(JSON.stringify(data)) }).catch( (error) => { console.log(`Error: $ ...

Having trouble setting the select value with JavaScript in the Selenium web driver

I am working on a web page that includes a cascaded dropdown feature. The data in the second dropdown appears to be generated via ajax based on the selection made in the first dropdown. Here is the code for the first select option: <select class="form- ...

Accessing a global variable within a jQuery .each function

I'm struggling to modify the global variable within an each function var total_ctc_change = 0; $('.table' + employeeid + ' thead th').each(function(index, value){ total_ctc_change++; }); ...

Assigning a Node.js exported function to a variable

Is there a way to save an exported function as a variable without executing it right away, in order to use Promise.all? I noticed that when I assign the function to a variable, it automatically runs. How can I prevent this from happening during assignment? ...

The AngularJS templates' use of the ternary operator

Is there a way to implement a ternary operation in AngularJS templates? I am looking for a way to apply conditionals directly in HTML attributes such as classes and styles, without having to create a separate function in the controller. Any suggestions wo ...

Loading GLTF model via XHR may take an infinite amount of time to reach full completion

I am attempting to load a GLTF model of a piano using XHR and showcase the loading progress on a webpage. The model is being loaded utilizing the Three.js library. On a local server, everything works perfectly - the loading percentage is shown accurately, ...

Encountering difficulty importing a class into the index.js file

225/5000 Hello, I seem to be facing a bit of trouble despite my efforts in trying to import a class into my index.js file. Here is what my index.js file looks like: import {Brandade} from "./modules/Brandade"; const brandade = new Brandade(&ap ...

Difficulty retrieving information using AngularJS service post selection of item

Currently, I am working on a project involving an AngularJS application. While using the service testPanelService, I encountered a problem where selecting an item from a list correctly logs the details of the selected item. However, when attempting to fetc ...