Google Frontline Worker - Bulk License Assignment (via Apps Script)

https://youtu.be/eoDedGEfdUg

Google Frontline Worker - Bulk License Assignment (via Apps Script)

Hey, Google Admins, this is Goldy again. Welcome back to the Google Frontline Worker SKU video series. In this video I'll talk to you about how you can leverage Google Apps script to bulk assign frontline worker license as to your users.

For that, let me share my screen and let's do this. I have this organizational unit called 'CI only' where I have two users inside.

1. Let me share my Screen here

If I scroll down on user's license section, you will see that this user does not have any license assigned. It is just as cloud identity free user.

3. If you Scroll down the page you can see that there is no Assigned License for this users

My objective is to bulk assign frontline worker SKU to these two users. In your case, there might be hundreds of users, it will still work the same way.

Okay, so let us leverage Google Apps script for this bulk Google Workspace frontline license assignment. You do not need to write the script as I have put it in the blog post below so you can just simply copy and paste it.

To start the process, go to your google sheets, and create a new new sheet, and give it a name (e.g flw license assignment), and then click on the 'Extensions' menu and then click on 'Apps Script' as shown in the screenshot below.

8. Go to Extentsions Click on Add Script

Now, you would see Google Apps script editor page, let us name our script (e.g flw script).

9. Again will give a name to our project is FLW

You script will now look like this with the name you gave it, and the default function in there.

10. Delete Everything you have Default function

Now, copy the script from below code block, remove the default apps script function, and paste this script.


------------------

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)
}

--------------------------

Your script will now look like the screenshot below.

11. Now paste the Script Which we Find in our Blog Post

This script will read the data from our Google sheet, so make the sheet name in the script (in line number 9) matches your actual google sheet name.

12. We will make sure that this is reading this Sheet and Copy this name

In my script above, the name of the sheet is 'Assign Frontline Licenses', so am giving my google sheet tab the same name as you see in the screenshot below.

13. Now Come Back Here and Rename the Sheet

Now you can add two columns in this google sheet (i) User Primary Email, and (ii) Status

You should enter the email address of the users in column one (one email per row), and leave the status (second) column blank as our script will output the status here.

15. Now Create this Sheet with User Primary Email and write the Script in the Coloumn

Now go back to your Google apps script, on the left navigation, click on services, and scroll down to 'Enterprise License Manager API', add this services as we'll need it to assign google workspace frontline licenses to our users in bulk.

17. Under Services When You Click On that You Need to Enable License API Click On Add Otherwise it Will not Work

Now we are all set to run our script, click on save to save all changes so far, and then click on play button to run the script as shown below.

19. Now go and Click on Run

As you are running the script for the first time, it will ask for your permissions.

22. We are Doing it First time So they are Asking for permission Click On review Permission

Now, select the admin account to provide permissions, and the script will run.

23. Select an Account Which you are using Click On Allow and Give the permission

Once the script runs, it will output the frontline license assignment status to our google sheet as you see below.

24. If We Come Back Here to the Second Coloumn It says License Assigned Successfully

Now if I go back to this user in my admin console, I see that the script assigned him a Google Workspace frontline license sku.

27. Lets Refresh the page and yes We Got it Assigned

I hope it was helpful a bit if you wanted to assign Google Workspace frontline licenses in bulk to your users, if you have any question, comment or feedback, don't hesitate to comment below.

Related Posts

....