নতুন কর্মচারী সরঞ্জাম অনুরোধ পরিচালনা করুন

কোডিং স্তর : শিক্ষানবিস
সময়কাল : 10 মিনিট
প্রকল্পের ধরন : একটি ইভেন্ট-চালিত ট্রিগার এবং একটি সময়-চালিত ট্রিগার সহ অটোমেশন

উদ্দেশ্য

  • বুঝুন সমাধান কি করে।
  • সমাধানের মধ্যে অ্যাপস স্ক্রিপ্ট পরিষেবাগুলি কী করে তা বুঝুন।
  • স্ক্রিপ্ট সেট আপ করুন।
  • স্ক্রিপ্ট চালান।

এই সমাধান সম্পর্কে

নতুন কর্মচারীদের সাধারণত আইটি থেকে সিস্টেম অ্যাক্সেস এবং সরঞ্জামের প্রয়োজন হয়। এই অনুরোধগুলি পরিচালনা করতে, আপনি ব্যবহারকারীদের জন্য Google ফর্মগুলির সাথে একটি ফর্ম তৈরি করতে পারেন যাতে কর্মচারীদের কী অ্যাক্সেস এবং ডিভাইসগুলি প্রয়োজন তা নির্দেশ করে৷ একবার IT অনুরোধটি সম্পূর্ণ করে এবং তার স্থিতি আপডেট করে, অনুরোধকারীরা একটি ইমেল বিজ্ঞপ্তি পাবেন।

সরঞ্জাম অনুরোধ ফর্মের স্ক্রিনশট

কিভাবে এটা কাজ করে

স্ক্রিপ্ট একটি সরঞ্জাম অনুরোধ ফর্ম তৈরি করে. আপনি নমুনা স্ক্রিপ্টের কোডে ফর্মের আইটেমগুলি কাস্টমাইজ করতে পারেন৷ যখন কেউ ফর্ম জমা দেয়, স্ক্রিপ্ট অনুরোধের জন্য নির্দিষ্ট যোগাযোগের বিন্দুতে একটি ইমেল বিজ্ঞপ্তি পাঠায়। একবার স্প্রেডশীটে অনুরোধের স্থিতি "সম্পূর্ণ"-এ পরিবর্তিত হলে স্ক্রিপ্টটি ফর্ম জমা দেওয়া ব্যক্তির কাছে একটি নিশ্চিতকরণ ইমেল পাঠায়৷

অ্যাপস স্ক্রিপ্ট পরিষেবা

এই সমাধানটি নিম্নলিখিত পরিষেবাগুলি ব্যবহার করে:

  • ফর্ম পরিষেবা - আইটি অনুরোধের জন্য ফর্ম তৈরি করে।
  • স্প্রেডশীট পরিষেবা - ডুপ্লিকেট প্রশমিত করার জন্য অনুরোধ ফর্মটি ইতিমধ্যেই বিদ্যমান কিনা তা পরীক্ষা করে। প্রয়োজন অনুযায়ী মুলতুবি এবং সম্পূর্ণ শীটে সরানোর মাধ্যমে ফর্ম প্রতিক্রিয়াগুলি পরিচালনা করে।
  • মেল পরিষেবা - অনুরোধ এবং সমাপ্তির বিজ্ঞপ্তি ইমেল তৈরি করে এবং পাঠায়।
  • স্ক্রিপ্ট পরিষেবা - ট্রিগার তৈরি করে। একটি ফর্ম জমা দেওয়া হলে একটি ফায়ার হয় এবং অন্যটি প্রতি পাঁচ মিনিটে একটি অনুরোধের স্ট্যাটাস "সম্পূর্ণ" হিসাবে চিহ্নিত করা হয়েছে কিনা তা পরীক্ষা করার জন্য ফায়ার করে৷

পূর্বশর্ত

এই নমুনা ব্যবহার করতে, আপনার নিম্নলিখিত পূর্বশর্ত প্রয়োজন:

  • একটি Google অ্যাকাউন্ট (Google Workspace অ্যাকাউন্টের জন্য অ্যাডমিনিস্ট্রেটরের অনুমোদনের প্রয়োজন হতে পারে)।
  • ইন্টারনেট অ্যাক্সেস সহ একটি ওয়েব ব্রাউজার।

স্ক্রিপ্ট সেট আপ করুন

অ্যাপস স্ক্রিপ্ট প্রকল্প তৈরি করুন

  1. কর্মচারী সরঞ্জামের অনুরোধের স্প্রেডশীট পরিচালনার একটি অনুলিপি করতে নিম্নলিখিত বোতামে ক্লিক করুন। এই সমাধানের জন্য অ্যাপস স্ক্রিপ্ট প্রকল্পটি স্প্রেডশীটের সাথে সংযুক্ত রয়েছে৷
    একটি কপি করো
  2. এক্সটেনশন > অ্যাপস স্ক্রিপ্টে ক্লিক করুন।
  3. REQUEST_NOTIFICATION_EMAIL ভেরিয়েবলের পাশে, নমুনা ইমেলটিকে আপনার ইমেল দিয়ে প্রতিস্থাপন করুন।
  4. Save এ ক্লিক করুন সেভ আইকন .

স্প্রেডশীট সেট আপ করুন

  1. স্প্রেডশীটে ফিরে যান এবং সরঞ্জামের অনুরোধ > সেট আপ ক্লিক করুন। এই কাস্টম মেনু প্রদর্শিত হওয়ার জন্য আপনাকে পৃষ্ঠাটি রিফ্রেশ করতে হতে পারে।
  2. অনুরোধ করা হলে, স্ক্রিপ্ট অনুমোদন করুন. যদি OAuth সম্মতি স্ক্রীন সতর্কতা প্রদর্শন করে, এই অ্যাপটি যাচাই করা হয়নি , তাহলে Advanced > Go to {Project Name} (অনিরাপদ) নির্বাচন করে চালিয়ে যান।

  3. সরঞ্জামের অনুরোধে ক্লিক করুন > আবার সেট আপ করুন

স্ক্রিপ্ট চালান

  1. টুলস > ম্যানেজ ফর্ম > লাইভ ফর্মে যান ক্লিক করুন।
  2. ফর্ম পূরণ করুন এবং জমা দিন।
  3. সরঞ্জাম অনুরোধ সম্পর্কে একটি বিজ্ঞপ্তি জন্য আপনার ইমেল চেক করুন.
  4. স্প্রেডশীটে ফিরে যান এবং মুলতুবি থাকা অনুরোধের শীটে, অনুরোধের স্থিতি সম্পূর্ণ করে পরিবর্তন করুন।
  5. 5 মিনিটের মধ্যে, স্ক্রিপ্টটি আপনাকে জানিয়ে আরেকটি ইমেল পাঠায় যে অনুরোধটি সম্পূর্ণ হয়েছে। স্ক্রিপ্টটি মুলতুবি থাকা অনুরোধ পত্র থেকে অনুরোধটিকে সম্পূর্ণ অনুরোধ শীটে নিয়ে যায়।

কোড পর্যালোচনা করুন

এই সমাধানের জন্য অ্যাপস স্ক্রিপ্ট কোড পর্যালোচনা করতে, নীচের উৎস কোড দেখুন ক্লিক করুন:

সোর্স কোড দেখুন

Code.gs

solutions/automations/equipment-requests/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.google.com/apps-script/samples/automations/equipment-requests

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Update this variable with the email address you want to send equipment requests to.
const REQUEST_NOTIFICATION_EMAIL = 'request_intake@example.com';

// Update the following variables with your own equipment options.
const AVAILABLE_LAPTOPS = [
  '15" high Performance Laptop (OS X)',
  '15" high Performance Laptop (Windows)',
  '15" high performance Laptop (Linux)',
  '13" lightweight laptop (Windows)',
];
const AVAILABLE_DESKTOPS = [
  'Standard workstation (Windows)',
  'Standard workstation (Linux)',
  'High performance workstation (Windows)',
  'High performance workstation (Linux)',
  'Mac Pro (OS X)',
];
const AVAILABLE_MONITORS = [
  'Single 27"',
  'Single 32"',
  'Dual 24"',
];

// Form field titles, used for creating the form and as keys when handling
// responses.
/**
 * Adds a custom menu to the spreadsheet.
 */
function onOpen() {
  SpreadsheetApp.getUi().createMenu('Equipment requests')
      .addItem('Set up', 'setup_')
      .addItem('Clean up', 'cleanup_')
      .addToUi();
}

/**
 * Creates the form and triggers for the workflow.
 */
function setup_() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  if (ss.getFormUrl()) {
    let msg = 'Form already exists. Unlink the form and try again.';
    SpreadsheetApp.getUi().alert(msg);
    return;
  }
  let form = FormApp.create('Equipment Requests')
      .setCollectEmail(true)
      .setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId())
      .setLimitOneResponsePerUser(false);
  form.addTextItem().setTitle('Employee name').setRequired(true);
  form.addTextItem().setTitle('Desk location').setRequired(true);
  form.addDateItem().setTitle('Due date').setRequired(true);
  form.addListItem().setTitle('Laptop').setChoiceValues(AVAILABLE_LAPTOPS);
  form.addListItem().setTitle('Desktop').setChoiceValues(AVAILABLE_DESKTOPS);
  form.addListItem().setTitle('Monitor').setChoiceValues(AVAILABLE_MONITORS);

  // Hide the raw form responses.
  ss.getSheets().forEach(function(sheet) {
    if (sheet.getFormUrl() == ss.getFormUrl()) {
      sheet.hideSheet();
    }
  });
  // Start workflow on each form submit
  ScriptApp.newTrigger('onFormSubmit_')
      .forForm(form)
      .onFormSubmit()
      .create();
  // Archive completed items every 5m.
  ScriptApp.newTrigger('processCompletedItems_')
      .timeBased()
      .everyMinutes(5)
      .create();
}

/**
 * Cleans up the project (stop triggers, form submission, etc.)
 */
function cleanup_() {
  let formUrl = SpreadsheetApp.getActiveSpreadsheet().getFormUrl();
  if (!formUrl) {
    return;
  }
  ScriptApp.getProjectTriggers().forEach(function(trigger) {
    ScriptApp.deleteTrigger(trigger);
  });
  FormApp.openByUrl(formUrl)
      .deleteAllResponses()
      .setAcceptingResponses(false);
}

/**
 * Handles new form submissions to trigger the workflow.
 *
 * @param {Object} event - Form submit event
 */
function onFormSubmit_(event) {
  let response = mapResponse_(event.response);
  sendNewEquipmentRequestEmail_(response);
  let equipmentDetails = Utilities.formatString('%s\n%s\n%s',
      response['Laptop'],
      response['Desktop'],
      response['Monitor']);
  let row = ['New',
    '',
    response['Due date'],
    response['Employee name'],
    response['Desk location'],
    equipmentDetails,
    response['email']];
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let sheet = ss.getSheetByName('Pending requests');
  sheet.appendRow(row);
}

/**
 * Sweeps completed and cancelled requests, notifying the requestors and archiving them
 * to the completed sheet.
 *
 * @param {Object} event
 */
function processCompletedItems_() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let pending = ss.getSheetByName('Pending requests');
  let completed = ss.getSheetByName('Completed requests');
  let rows = pending.getDataRange().getValues();
    for (let i = rows.length; i >= 2; i--) {
      let row = rows[i -1];
      let status = row[0];
      if (status === 'Completed' || status == 'Cancelled') {
          pending.deleteRow(i);
          completed.appendRow(row);
          console.log("Deleted row: " + i);
          sendEquipmentRequestCompletedEmail_({
            'Employee name': row[3],
            'Desk location': row[4],
            'email': row[6],
          });
        }
      };
}

/**
 * Sends an email notification that a new equipment request has been submitted.
 *
 * @param {Object} request - Request details
 */
function sendNewEquipmentRequestEmail_(request) {
  let template = HtmlService.createTemplateFromFile('new-equipment-request.html');
  template.request = request;
  template.sheetUrl = SpreadsheetApp.getActiveSpreadsheet().getUrl();
  let msg = template.evaluate();
  MailApp.sendEmail({
    to: REQUEST_NOTIFICATION_EMAIL,
    subject: 'New equipment request',
    htmlBody: msg.getContent(),
  });
}

/**
 * Sends an email notifying the requestor that the request is complete.
 *
 * @param {Object} request - Request details
 */
function sendEquipmentRequestCompletedEmail_(request) {
  let template = HtmlService.createTemplateFromFile('request-complete.html');
  template.request = request;
  let msg = template.evaluate();
  MailApp.sendEmail({
    to: request.email,
    subject: 'Equipment request completed',
    htmlBody: msg.getContent(),
  });
}

/**
 * Converts a form response to an object keyed by the item titles. Allows easier
 * access to response values.
 *
 * @param {FormResponse} response
 * @return {Object} Form values keyed by question title
 */
function mapResponse_(response) {
  let initialValue = {
    email: response.getRespondentEmail(),
    timestamp: response.getTimestamp(),
  };
  return response.getItemResponses().reduce(function(obj, itemResponse) {
    let key = itemResponse.getItem().getTitle();
    obj[key] = itemResponse.getResponse();
    return obj;
  }, initialValue);
}

new-equipment-request.html

solutions/automations/equipment-requests/new-equipment-request.html
<!DOCTYPE html>
<!--
 Copyright 2022 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<html>
  <body>
    <p>
    A new equipment request has been made by <?= request.email ?>.
    </p>

    <p>
    Employee name: <?= request['Employee name'] ?><br/>
    Desk location name: <?= request['Desk location'] ?><br/>
    Due date: <?= request['Due date'] ?><br/>
    Laptop model: <?= request['Laptop'] ?><br/>
    Desktop model: <?= request['Desktop'] ?><br/>
    Monitor(s): <?= request['Monitor'] ?><br/>
    </p>

    See <a href="<?= sheetUrl ?>">the spreadsheet</a> to take or assign this item.
  </body>
</html>

request-complete.html

solutions/automations/equipment-requests/request-complete.html
<!DOCTYPE html>
<!--
 Copyright 2022 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<html>
  <body>
    <p>
    An equipment request has been completed.
    </p>

    <p>
    Employee name: <?= request['Employee name'] ?><br/>
    Desk location name: <?= request['Desk location'] ?><br/>
    </p>
  </body>
</html>

অবদানকারী

এই নমুনা Google ডেভেলপার বিশেষজ্ঞদের সাহায্যে Google দ্বারা রক্ষণাবেক্ষণ করা হয়।

পরবর্তী পদক্ষেপ