Make list from Workdrive Folder

Make list from Workdrive Folder

Hi,

Today, my challenge is to simplify and optimize my drop-down list where I retrieve the list of files present in a WorkDrive folder.

I had to create a custom function to replace and display special characters.

Then, I need the file ID to open it in one part of my application, but I would like the file name to be displayed.

I was unable to make the file name visible, and then its ID used. I had to create the file name + its ID, then in the other part of my application, I split the name to retrieve only its ID.

I don't know if I'm explicit enough, I'll try to provide you with images and code to better understand.

File name in Workdrive :

File name in my List Field :


My custom function to decode HTML :
  1. string decodeHtml(string text)
  2. {
  3. text = text.replaceAll("é","é");
  4. text = text.replaceAll("è","è");
  5. text = text.replaceAll("ê","ê");
  6. text = text.replaceAll("à","à");
  7. text = text.replaceAll("â","â");
  8. text = text.replaceAll("î","î");
  9. text = text.replaceAll("ô","ô");
  10. text = text.replaceAll("û","û");
  11. text = text.replaceAll("ç","ç");
  12. text = text.replaceAll(" "," ");
  13. // Espace
  14. return text;
  15. }

My Deluge Script to list all files in WorkDrive with my custom function :
  1. header = Map();
  2. header.put("Accept","application/vnd.api+json");
  3. response = invokeurl
  4. [
  5. url :"https://www.zohoapis.com/workdrive/api/v1/files/FOLDER_ID/files"
  6. type :GET
  7. headers:header
  8. connection:"creatorcon"
  9. ];
  10. files = response.get("data");
  11. nameList = List();
  12. for each  file in files
  13. {
  14. fileId = file.get("id");
  15. fileName = thisapp.decodeHtml(file.get("attributes").get("display_attr_name")) + " - " + file.get("id");
  16. nameList.add(fileName);
  17. }
  18. input.choose_xls_file:ui.add(nameList);

My Deluge script in my application where I split the name of item in list :
  1. inputString = input.choose_xls_file;
  2. separatorIndex = inputString.indexOf(" - ");
  3. if(separatorIndex != -1)
  4. {
  5. getItemId = inputString.substring(separatorIndex + 3);
  6. getFileName = inputString.substring(0,separatorIndex);
  7. }
  8. queryData = Map();
  9. response = zoho.sheet.getSheets(getItemId,"creatorcon");
  10. worksheetNames = response.get("worksheet_names");
  11. worksheetName = "";
  12. for each  worksheet in worksheetNames
  13. {
  14. worksheetName = worksheet.get("worksheet_name");
  15. worksheetId = worksheet.get("worksheet_id");
  16. }
  17. responseV2 = zoho.sheet.getRecords(getItemId,worksheetName,queryData,"creatorcon");

Please, can you help me to optimize this ?
I'm sure there is a way to make a list with the file names, but use their IDs without having to display them.

Thanks all :)