2017-07-18 7 views
0

私はスラックボットのフィールドブックにコードレットを作成しています。これは、要求された日付と一致するすべてのレコードを返すことを意味します。今は最初のレコードだけを返すように設定されていますが、すべて必要です。私はこれについてかなり新しいです、これは基本的な質問であれば謝りますが、どんな助けも素晴らしいでしょう。以下は私がこれまで持っていたものです。Fieldbook Codelet - 一致するすべてのレコードを返さない

var _ = require('underscore'); 
var s = require('underscore.string'); 

exports.endpoint = exports.endpoint = function (request, response) { 
    var jobDate = request.body.text; 
    // Get the date from Job Notes 
    var date = `${(jobDate)}`; 

    // Find all records with the given date 
    var query = {date: date}; 
    return client.list('job_notes', query).then(function (records) { 
     // This is only pulling the first record 

私は、与えられた日付と一致するすべてのレコードが必要です。これはforループが必要と思われる場所です。

 var record = records[0]; 

     if (!record) return `No data found for ${jobDate}`; // Did not match any record 

     var employee = record.employee[0]; 
     var job = record.job[0]; 

     var attributes = [ 
     {title: 'Date', value:date, short: true}, 
     {title: 'Time', value:record.time, short: true}, 
     {title: 'Employees', value:employee, short: true}, 
     {title: 'Job', value:job, short: true}, 
     {title: 'Note', value:record.note, short: true}, 
     ]; 

     return { 
     attachments: [{ 
      fallback: record.name, 
      title: record.name, 
      fields: attributes, 
     }] 
    } 
    }) 
} 

答えて

0

は、私はあなたの質問は、forループで変数recordsに渡された項目のリストを反復処理に関係していると信じています。これは次のコードで行うことができます:

return client.list('job_notes', query).then(function(records) { 
    for (i = 0; i < records.length; i++) { 
     var record = records[i]; 

     if (!record) return `No data found for ${jobDate}`; // Did not match any record 

     var employee = record.employee[0]; 
     var job = record.job[0]; 

     var attributes = [ 
      {title: 'Date', value:date, short: true}, 
      {title: 'Time', value:record.time, short: true}, 
      {title: 'Employees', value:employee, short: true}, 
      {title: 'Job', value:job, short: true}, 
      {title: 'Note', value:record.note, short: true}, 
     ]; 


     return { 
      attachments: [{ 
       fallback: record.name, 
       title: record.name, 
       fields: attributes, 
      }] 
     } 
    } 
}) 

+0

ありがとうございます、私はこれを試し、あなたにお知らせします。私は迅速な対応に感謝します! – chasewarner

関連する問題