为什么我没有定义“ userId”。

发布于 2025-02-10 01:23:27 字数 1315 浏览 1 评论 0原文

您能帮我提供以下脚本吗?我得到的“未定义”。

我正在尝试根据 https://wwww.youtube.com/watch? v = e4ktaytoeya

function updateLicenses() {
    var updateSheet = SpreadsheetApp.getActive() .getSheetByName("Update Licenses")
    var data = updateSheet.getRange(2, 1, updateSheet.getLastRow() - 1, 3).getValues()
  var fileArray = [
        ["License Update Status"]
    ]


    // Loop through all user provided google sheet rows and call Directy API with it

    data.forEach(function(item) {
        var status = "License Assigned Successfully"
        try {
            var userId = item[0]
            var apiCall = AdminLicenseManager.LicenseAssignments.patch({
          
            // enter new license details here
                "productID": "Google-Apps",
                "skuID": "1010020027",
                "userID": userID
           }, "Google-Apps", "1010020028", userId)  // enter exiting/assigned license details here
              
      } catch (e) {
          var status = e.message
      }
      fileArray.push([status])
    })
      
    updateSheet.getRange(1, 2, fileArray.length, fileArray[0].length).setValues(fileArray)

    //AdminLicenseManager.LicenseAssignments.patch()
}

Could you please help me with the following script? I'm getting "userID is not defined".

I'm trying to bulk modify licenses based on https://www.youtube.com/watch?v=e4KTAytOeyA

function updateLicenses() {
    var updateSheet = SpreadsheetApp.getActive() .getSheetByName("Update Licenses")
    var data = updateSheet.getRange(2, 1, updateSheet.getLastRow() - 1, 3).getValues()
  var fileArray = [
        ["License Update Status"]
    ]


    // Loop through all user provided google sheet rows and call Directy API with it

    data.forEach(function(item) {
        var status = "License Assigned Successfully"
        try {
            var userId = item[0]
            var apiCall = AdminLicenseManager.LicenseAssignments.patch({
          
            // enter new license details here
                "productID": "Google-Apps",
                "skuID": "1010020027",
                "userID": userID
           }, "Google-Apps", "1010020028", userId)  // enter exiting/assigned license details here
              
      } catch (e) {
          var status = e.message
      }
      fileArray.push([status])
    })
      
    updateSheet.getRange(1, 2, fileArray.length, fileArray[0].length).setValues(fileArray)

    //AdminLicenseManager.LicenseAssignments.patch()
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2025-02-17 01:23:27

基于该视频。您是否将表的点击命名为更新许可证

如视频中所示的A列中的用户ID是否是? (如果您更改了电子邮件的列,是var data指向该列吗?)

我在视频所有者的页面,他更新了代码:

function assignLicenses() {

    // Add SKU details here, below ones are for frontline worker
    var productId = "Google-Apps"
    var skuId = 1010020030

    // Get Google Sheet and read the user emails from it, we'll use these to assign licenses

    var assignmentSheet = SpreadsheetApp.getActive().getSheetByName("Assign Frontline Licenses")
    var data = assignmentSheet.getRange(2, 1, assignmentSheet.getLastRow() - 1, 2).getValues()

    // Create an array to store the results from API, instead of appendRow, we'll rather save output to this array, and then write back to sheet at once
    var fileArray = [
        ["License Assignment Status"]
    ]

    // Loop through the google sheet values, and call License API to assign the given license
    data.forEach(function(item) {
        var status = "Licese Assigned Successfully"
        try {
            //var productId = getSkuDetails(item[1])
            var apiCall = AdminLicenseManager.LicenseAssignments.insert({
                "userId": item[0]
            }, productId, skuId)
        }

        // Catch Errors (if any)
        catch (e) {
            var status = e.message
        }

        // Write the output data back to our array
        fileArray.push([status])
    })


    // Write the results from array to our google sheet
    assignmentSheet.getRange(1, 2, fileArray.length, fileArray[0].length).setValues(fileArray)
}

如果您有疑问,请告诉我。

Based on that video. Did you rename the tap of the Sheet as Update Licenses?

enter image description here

Are the user IDs in column A, as shown in the video, or a different Column? (if you change the column for the emails, is the var data pointing to that column?)

I searched on the page of the owner of the video, and he updated his code:

function assignLicenses() {

    // Add SKU details here, below ones are for frontline worker
    var productId = "Google-Apps"
    var skuId = 1010020030

    // Get Google Sheet and read the user emails from it, we'll use these to assign licenses

    var assignmentSheet = SpreadsheetApp.getActive().getSheetByName("Assign Frontline Licenses")
    var data = assignmentSheet.getRange(2, 1, assignmentSheet.getLastRow() - 1, 2).getValues()

    // Create an array to store the results from API, instead of appendRow, we'll rather save output to this array, and then write back to sheet at once
    var fileArray = [
        ["License Assignment Status"]
    ]

    // Loop through the google sheet values, and call License API to assign the given license
    data.forEach(function(item) {
        var status = "Licese Assigned Successfully"
        try {
            //var productId = getSkuDetails(item[1])
            var apiCall = AdminLicenseManager.LicenseAssignments.insert({
                "userId": item[0]
            }, productId, skuId)
        }

        // Catch Errors (if any)
        catch (e) {
            var status = e.message
        }

        // Write the output data back to our array
        fileArray.push([status])
    })


    // Write the results from array to our google sheet
    assignmentSheet.getRange(1, 2, fileArray.length, fileArray[0].length).setValues(fileArray)
}

Let me know if you have questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文