Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Google Apps Script phone numbers from AD

I’m trying to create a script in Google Apps Script that gets users' phone numbers from AD and copies them into Google Sheets.

try {
      if(user.phones[0].type = 'home'){
        prop.push(user.phones[0].value);
      }
      if (user.phones[1].type = 'mobile'){
        prop.push(user.phones[1].value );
      }
      if(user.phones[2].type = 'work'){
        prop.push(user.phones[2].value);
      }
      else{
        prop.push('');
      }
      
    }
      catch(err){
      prop.push('');
    }

Now that does work, but it puts numbers in unwanted cell order. It seems to type: ‘work’ ‘home’ ‘mobile’. Also, if the user does not have 3 of those numbers, so f.e. Only ‘mobile’, this script puts it first where ‘work’ should be. I was hoping this code would put them in a specific cell order: ‘home’, ‘mobile’, ‘work’. Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Instead of = use ===
  2. The first two if hasn't and else. If you don't want misplaced data, then you should add else{ prop.push(''); } after each of them.
  3. Regarding the order, you might have to create an Array of empty strings and replace the one that corresponds to each phone type by the corresponding value.

The following example uses Array.prototype.forEach and switch instead of several if

const prop = new Array(4).fill('');
user.phones.forEach(phone => {

  switch(phone.type){
     case 'home':
       prop[0] = phone.value;
     break;
     case 'work':
       prop[1] = phone.value;
     break;
     case 'mobile':
       prop[2] = phone.value;
     break;
     default: // This will manage other phone types
       prop[3] = prop[3].length === 0 ? phone.value : [prop[3], phone.value].join(',');
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda