Hi team!
My app creates a new folder when a new sale is done (an automation that creates a dummy pdf with route of the file containing /data/appsheet/newsalecode/Dummyfile
Is it possible to modiffy via API the name of the folder after?
I know its a little complicated but sometimes the sale code contains some extra info that is added during the sale and not at the beggining.
thanks as always!
Probably not with the API, but it likely is possible using an automation in conjunction with Google Apps Script (assuming your file store is Google Drive?). Are you recording the file folder ID as part of your process?
Hi Markus, I did not see this message, so sorry.
My folder is created by appsheet⦠Can I make that folder ID is auto saved? Any idea?
THANKS!!!
You are saying that Appsheet creates a new folder? Is this done through an automation or are you referring to the the default folder that Appsheet creates when you add a new column for a file?
What I am trying to point out is if you already have an automation that creates a new file folder in GDrive then it would likely just take a few more steps in the same process to rename the folder. But I would need to understand a little more of your process.
I created a bot that creates a new pdf file.
in the folder path i added like this: appsheet/folder1/[customer puchase id]/
so it creates the customer folder if it was not created before ā¦
the point is sometimes we change something of the purchase and it would be cool to update the folder nameā¦
(I used example just to explain myself)
So you are saying the [customer purchase id] might change at some point? And at that point you would want to rename the folder?
In this case Google Apps Script would be your friend. I would suggest adding a new bot with a data change event on updates only. The condition for execution probably should be [_THISROW_BEFORE].[customer purchase id] <> [_THISROW_AFTER].[customer purchase id]. Create a google apps script file with a function like this:
function changeFolderName(oldpurchaseid, newpurchaseid) {
let folders = DriveApp.getFoldersByName(oldpurchaseid);
if(folders.hasNext()) {
let folder = folders.next();
folder.setName(newpurchaseid);
}
}
In your process you would select ārun a taskā => ārun a scriptā. Select the google apps script file, you may have to authorize the script first, then select function, then it will bring up two fields for your variables in your function.
For oldpurchaseid the setting would be [_THISROW_BEFORE].[customer purchase id]
For newpurchaseid the setting would be [_THISROW_AFTER].[customer purchase id]
For full disclosure, your app needs to run as the creator, or the app user needs to have full access to the parent folder of where this folder is stored in the case where you run the app as the user. Additional finagling might still be required since this is just off the top of my head and have not tested this.
Thanks x10000
I will try later.
Every day more fascinared of what appsheet can do!
Hi Markus, I could not yet apply this in my App but this is a supur cool and complete solution. Thanks a lot foy your time. Have a nice week
Please help me out with a similar script for a daily change of date.
The folder name is CL&Resume 6-30-25, and I need that date to change daily to the current date⦠tomorrow will be 7-1-25
I appreciate your support.
Similar script, but the variables you need to pass from your bot would be olddate = TODAY()-1 and newdate = TODAY()
1 Like
Would this be correct"
"
function changeFolderName(6-30-2025 = TODAY(7-1-2025)-1, 7-1-2025 = TODAY(7-1-2025)) {
let folders = DriveApp.getFoldersByName(6-30-2025 = TODAY(7-1-2025)-1);
if(folders.hasNext()) {
let folder = folders.next();
folder.setName(newpurchaseid);
}
}"
Thatās what I did, but it doesnāt give me the option to run it. The run button is greyed out. Please help. Thanks a lot.
Kwasi
Hi Markus, Iāve just tried the following but even the run is greyed out. What am I doing wrong? Please, help.
"function changeFolderName(6-30-2025 = TODAY(7-1-2025)-1, 7-1-2025 = TODAY(7-1-2025)) {
let folders = DriveApp.getFoldersByName(6-30-2025 = TODAY(7-1-2025)-1);
if(folders.hasNext()) {
let folder = folders.next();
folder.setName(7-1-2025);
}
}"
Thanks.
Apps Script (GAS) has no way to interpret the functions from Appsheet. So incorporating āTODAY()ā has no meaning within GAS. So your function in GAS should only be this:
function changeFolderName(olddate, newdate) {
let folders = DriveApp.getFoldersByName(olddate);
if(folders.hasNext()) {
let folder = folders.next();
folder.setName(newdate);
}
}
Then you set up a bot with a scheduled event:
Then under process you add a step and configure it to run a script like so:
The formula to enter for the variable for olddate is:
TEXT(TODAY()-1, "M-D-YYYY")
The formula to enter for newdate is:
TEXT(TODAY(), "M-D-YYYY")
Now you will also need to observe that this script will search for every single folder within the Google Drive tied to the Appsheet project, so if you have the same folder naming convention anywhere else it will do the same name change update.
Also, since you asked under an Appsheet question thread I assumed you want this to run from Appsheet rather than directly from GAS. If you are wanting to establish a trigger from GAS directly then the function within GAS needs to change.
1 Like
Thanks a bunch. I am trying it out. Thanks a bunch.
Keep in mind that you may also need to authorize the script first from within Appsheet. If that is the case there should be a button under the script task that says āAuthorizeā.
1 Like