Bridge Javascript/Call API & Control Center
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:
- Event
- New row added to the Summary Sheet (Control Center)
- Get Row (Bridge)
- Get the name of the project (Also the name of the project folder)
- 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).
- Javascript (Bridge)
- List the folders in a specific workspace and find the one that is equal to the name of the project.
- Grab the sheet that is within that folder.
- Move to the folder that is equal to the Team Member that was collected in Step 2.
- 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
-
@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.
- Use Bridge to trigger off of a row being added to the summary sheet from a control center project.
- New State: Get Row
- Use Bridge to get row
- The row contains the project name and employee name.
- Use Bridge to get row
- New State: Get Project Folder
- Use the API with the workspace ID that we are pushing the projects to and list out the folders in that workspace.
- Use JS to see which of the folder names contains the project name that we got from step 2a.
- New State: Get Project Sheet/Employee Folder
- Use the API to get the sheet ID from the sheet in the folder from step 3b.
- Use JS to see which of the folder names (step 3a) contains the employee name that we got from step 2a.
- New State: Get Destination Folder
- Use the API to list the folders under the folder from step 4b.
- Use JS to see which of the folder names is equal to "Group Sheets".
- New State: Move Sheet
- Use the API to move the sheet (step 4a) to the "Group Sheets" folder (step 5b).
- New State: Delete Project Folder
- 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
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
-
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,
GenevieveJoin us at Smartsheet ENGAGE 2024 🎉
October 8 - 10, Seattle, WA | Register now -
@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.
- Use Bridge to trigger off of a row being added to the summary sheet from a control center project.
- New State: Get Row
- Use Bridge to get row
- The row contains the project name and employee name.
- Use Bridge to get row
- New State: Get Project Folder
- Use the API with the workspace ID that we are pushing the projects to and list out the folders in that workspace.
- Use JS to see which of the folder names contains the project name that we got from step 2a.
- New State: Get Project Sheet/Employee Folder
- Use the API to get the sheet ID from the sheet in the folder from step 3b.
- Use JS to see which of the folder names (step 3a) contains the employee name that we got from step 2a.
- New State: Get Destination Folder
- Use the API to list the folders under the folder from step 4b.
- Use JS to see which of the folder names is equal to "Group Sheets".
- New State: Move Sheet
- Use the API to move the sheet (step 4a) to the "Group Sheets" folder (step 5b).
- New State: Delete Project Folder
- 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
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!
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 62.9K Get Help
- 379 Global Discussions
- 210 Industry Talk
- 441 Announcements
- 4.5K Ideas & Feature Requests
- 139 Brandfolder
- 129 Just for fun
- 130 Community Job Board
- 449 Show & Tell
- 30 Member Spotlight
- 1 SmartStories
- 300 Events
- 33 Webinars
- 7.3K Forum Archives