Bridge Javascript/Call API & Control Center

Options
Coop22
Coop22 ✭✭✭✭

Hello all,

I have had some success with using the Smartsheet API using the PythonSDK. I am currently using Control Center to create some projects, but they get created in a workspace instead of a folder within a workspace. I have had some success with using the Smartsheet API using the PythonSDK to do something similar, so I figured I could fix my issue with the API. However, I don't have the ability right now to set up a Python environment with a "listener" for a lack of better terms. So, the next thought was to use Bridge as the listener and use the Javascript component along with the JavascriptSDK to move the sheets to the folder that I want. The flow is like this:


  1. Event
    1. New row added to the Summary Sheet (Control Center)
  2. Get Row (Bridge)
    1. Get the name of the project (Also the name of the project folder)
    2. Get the corresponding Team Member (Also the name of the Level 1 folder that holds the Level 2 folder that we will be placing the sheet in).
  3. Javascript (Bridge)
    1. List the folders in a specific workspace and find the one that is equal to the name of the project.
    2. Grab the sheet that is within that folder.
    3. Move to the folder that is equal to the Team Member that was collected in Step 2.
    4. Place the sheet from 3b in the level 2 folder that is equal to "Group Sheets".

I'm not sure how to get this to work correctly as it seems that everytime I try to even just LIST the folders in the workspace, it doesn't work. I'm assuming that there is going to have to be some cross-play between the Call API and Javascript modules possibly?

Best Answer

  • Coop22
    Coop22 ✭✭✭✭
    Answer ✓
    Options

    @Genevieve P. Thank you for that! After some trial and error, we were finally able to get a solution! We were able to do it fairly similarly to what you have, but with a bit of additional javascript which allows it to be dynamic when we have multiple employees in this workspace.

    1. Use Bridge to trigger off of a row being added to the summary sheet from a control center project.
    2. New State: Get Row
      1. Use Bridge to get row
        1. The row contains the project name and employee name.
    3. New State: Get Project Folder
      1. Use the API with the workspace ID that we are pushing the projects to and list out the folders in that workspace.
      2. Use JS to see which of the folder names contains the project name that we got from step 2a.
    4. New State: Get Project Sheet/Employee Folder
      1. Use the API to get the sheet ID from the sheet in the folder from step 3b.
      2. Use JS to see which of the folder names (step 3a) contains the employee name that we got from step 2a.
    5. New State: Get Destination Folder
      1. Use the API to list the folders under the folder from step 4b.
      2. Use JS to see which of the folder names is equal to "Group Sheets".
    6. New State: Move Sheet
      1. Use the API to move the sheet (step 4a) to the "Group Sheets" folder (step 5b).
    7. New State: Delete Project Folder
      1. Use the API to delete the project folder (step 3b).

    We used the https://api.smartsheet.com/2.0/ for the base URL and then the documentation from https://smartsheet.redoc.ly/?_gl=1*1kk6t8a*_ga*MjUzODA3NTQ1LjE3MDgzODQzMDk.*_ga_ZYH7XNXMZK*MTcxMzgwMzU4OS45NC4xLjE3MTM4MDQwNTMuNTkuMC4w&_ga=2.255678600.1272401998.1713800142-253807545.1708384309#section/Introduction to do the endpoints.

    We were then able to use the below JavaScript through each step to determine which folders we were wanting to use.
    function getFolderIdByName(folders, searchName) {
    const folder = folders.find(folder => folder.name.includes(searchName));
    if (folder) {
    return folder.id;
    } else {
    return 'Folder not found';
    }
    }

    const folders = folderArray;
    const folderId = getFolderIdByName(folders, searchName);
    return folderId;
    The folderArray and searchName were set in the Bridge JavaScript Script Parameters. The folderArray was set to the folder arrays that we were getting from the API calls and the searchName was set to the folders that we were trying to find (Project Name(Step 2a), Employee Name (Step 2a), or Group Sheets (Hard Coded)).
    The folder.name.includes() allowed us to not have to specify the whole name for the folder and instead just include the specific part that we were capturing in the summary sheet.

    Now onto step 2 (or would it be 8?) for when the project is complete, we are going to make a copy of the sheet, save the copy to a historical folder, then wipe the original so that it can be used again. My use-case is a project sheet that is refreshed annually. No need to archive the projects in Control Center, especially since Control Center has issues with creating projects with the same name a second time, and not being able to effectively archive the actual project sheet if it is moved from the original project folder!

Answers

  • Genevieve P.
    Genevieve P. Employee Admin
    Options

    Hey @Coop22

    I have to admit I'm not very good with Javascript, so I would do all this with multiple API Utilities. I'm pretty certain there would be a better way to do this, and yes, perhaps Javascript would be better… but with my minimal API knowledge I was able to get the following steps to work. Keep in mind the Folder Names would need to be unique each time.

    After your steps 1&2:

    3 - API Utility (Bridge) - Find Current Folder

    • Search - https://smartsheet.redoc.ly/tag/search#operation/list-search
    • Parameters:
      • query = {{Run log reference to Project Name}}
      • scopes = folderNames

    4 - API Utility (Bridge - under a new State) - Get Current Folder Items

    • Get Folder - https://smartsheet.redoc.ly/tag/folders#operation/get-folder
    • Reference the Run Log data that contains the Folder ID from the previous call in the URL

    5 - API Utility (Bridge - under a new State) - Get User Folder

    • Search - https://smartsheet.redoc.ly/tag/search#operation/list-search
    • Parameters:
      • query = {{Run log reference to Person's Name}}
      • scopes = folderNames

    6 - API Utility (Bridge - under a new State) - Get User Folder Items to find subFolder

    • Get Folder - https://smartsheet.redoc.ly/tag/folders#operation/get-folder
    • Reference the Run Log data that contains the Folder ID from the previous call in the URL

    7 - API Utility (Bridge - under a new State) - Move sheet from step 4 into the folder from step 6

    • Move Sheet - https://smartsheet.redoc.ly/tag/sheets#operation/move-sheet
    • Sheet ID in URL = {{Run log reference to the ID from step 4}}
    • destinationId = {{Run log reference to the folder ID from step 6}}


    If you find an easier way to do this I would love to see your solution!


    Thanks,
    Genevieve

  • Coop22
    Coop22 ✭✭✭✭
    Answer ✓
    Options

    @Genevieve P. Thank you for that! After some trial and error, we were finally able to get a solution! We were able to do it fairly similarly to what you have, but with a bit of additional javascript which allows it to be dynamic when we have multiple employees in this workspace.

    1. Use Bridge to trigger off of a row being added to the summary sheet from a control center project.
    2. New State: Get Row
      1. Use Bridge to get row
        1. The row contains the project name and employee name.
    3. New State: Get Project Folder
      1. Use the API with the workspace ID that we are pushing the projects to and list out the folders in that workspace.
      2. Use JS to see which of the folder names contains the project name that we got from step 2a.
    4. New State: Get Project Sheet/Employee Folder
      1. Use the API to get the sheet ID from the sheet in the folder from step 3b.
      2. Use JS to see which of the folder names (step 3a) contains the employee name that we got from step 2a.
    5. New State: Get Destination Folder
      1. Use the API to list the folders under the folder from step 4b.
      2. Use JS to see which of the folder names is equal to "Group Sheets".
    6. New State: Move Sheet
      1. Use the API to move the sheet (step 4a) to the "Group Sheets" folder (step 5b).
    7. New State: Delete Project Folder
      1. Use the API to delete the project folder (step 3b).

    We used the https://api.smartsheet.com/2.0/ for the base URL and then the documentation from https://smartsheet.redoc.ly/?_gl=1*1kk6t8a*_ga*MjUzODA3NTQ1LjE3MDgzODQzMDk.*_ga_ZYH7XNXMZK*MTcxMzgwMzU4OS45NC4xLjE3MTM4MDQwNTMuNTkuMC4w&_ga=2.255678600.1272401998.1713800142-253807545.1708384309#section/Introduction to do the endpoints.

    We were then able to use the below JavaScript through each step to determine which folders we were wanting to use.
    function getFolderIdByName(folders, searchName) {
    const folder = folders.find(folder => folder.name.includes(searchName));
    if (folder) {
    return folder.id;
    } else {
    return 'Folder not found';
    }
    }

    const folders = folderArray;
    const folderId = getFolderIdByName(folders, searchName);
    return folderId;
    The folderArray and searchName were set in the Bridge JavaScript Script Parameters. The folderArray was set to the folder arrays that we were getting from the API calls and the searchName was set to the folders that we were trying to find (Project Name(Step 2a), Employee Name (Step 2a), or Group Sheets (Hard Coded)).
    The folder.name.includes() allowed us to not have to specify the whole name for the folder and instead just include the specific part that we were capturing in the summary sheet.

    Now onto step 2 (or would it be 8?) for when the project is complete, we are going to make a copy of the sheet, save the copy to a historical folder, then wipe the original so that it can be used again. My use-case is a project sheet that is refreshed annually. No need to archive the projects in Control Center, especially since Control Center has issues with creating projects with the same name a second time, and not being able to effectively archive the actual project sheet if it is moved from the original project folder!