Google Drive File Copy

Copies a file on Google Drive and save it to the specified directory. Preparing a file to be a template and it will be a copy automatically at the Start of a new Issue.

    A. Set OAuth2 Config Name (at [OAuth 2.0 Setting])Single-line inputRequired
    B. Select STRING/SELECT DATA for Source File IdData selectString(single line)orSelect(radio/select/search)Required
    C. Select STRING/SELECT DATA for Parent Folder IdData selectString(single line)orSelect(radio/select/search)Required
    D. Select STRING DATA for Name of New FileData selectString(single line)Required
    E. Set "true" if Team Drives accessSingle-line input
    F. Select STRING DATA for New File Id (update)Data selectString(single line)
    G. Select STRING DATA for New File MimeType (update)Data selectString(single line)
    X. Select STRING DATA for Access Log (update)Data selectString(multiple line)
    -variable namevariable label
    Aconf_OAuth2Set OAuth2 Config Name (at [OAuth 2.0 Setting])
    Bconf_DataIdBSelect STRING/SELECT DATA for Source File Id
    Cconf_DataIdCSelect STRING/SELECT DATA for Parent Folder Id
    Dconf_DataIdDSelect STRING DATA for Name of New File
    Econf_SupportsTeamDrivesSet "true" if Team Drives access
    Fconf_DataIdFSelect STRING DATA for New File Id (update)
    Gconf_DataIdGSelect STRING DATA for New File MimeType (update)
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Google Drive Files Copy via Drive API v3 (ver. 20170821)
    // (c) 2017, Questetra, Inc. (the MIT License)
    
    ////// == 工程コンフィグの参照 / Config Retrieving ==
    var oauth2  = configs.get( "conf_OAuth2" ) + "";
    // Convert from 'java.lang.String' to 'JavaScript string' by '+""'
    var dataIdB = configs.get( "conf_DataIdB" ) + ""; // Data Identification Number (e.g. "9")
    var dataIdC = configs.get( "conf_DataIdC" ) + ""; 
    var dataIdD = configs.get( "conf_DataIdD" ) + "";
    var supportsTeamDrives = configs.get( "conf_SupportsTeamDrives" ) + "";
    var dataIdF = configs.get( "conf_DataIdF" ) + "";
    var dataIdG = configs.get( "conf_DataIdG" ) + "";
    var dataIdX = configs.get( "conf_DataIdX" ) + "";
    
    ////// == ワークフローデータの参照 / Data Retrieving ==
    var fileId = ""; // e.g. "1PEZ5KEZc0RkUn7AbAe2lYaHXzbJ9jnZ2swIWPszRz6U"
    if( engine.findDataDefinitionByNumber( dataIdB ).matchDataType( "STRING_TEXTFIELD" ) ){
      fileId = data.get( dataIdB ) + ""; // convert to JavaScript string
    }else if( engine.findDataDefinitionByNumber( dataIdB ).matchDataType( "SELECT_SINGLE" ) ){
      fileId = data.get( dataIdB ).get(0).getValue() + "";
    }
    var parent = ""; // e.g. "0B0P-A0cQe_0gTnp0aDZmM0VYbGs"
    if( engine.findDataDefinitionByNumber( dataIdC ).matchDataType( "STRING_TEXTFIELD" ) ){
      parent = data.get( dataIdC ) + "";
    }else if( engine.findDataDefinitionByNumber( dataIdC ).matchDataType( "SELECT_SINGLE" ) ){
      parent = data.get( dataIdC ).get(0).getValue() + "";
    }
    var name   = data.get( dataIdD ) + "";
    
    ////// == 演算 / Calculating ==
    // preparing for API Request
    var apiRequest = httpClient.begin(); // HttpRequestWrapper
    
    // preparing for API Request (OAuth2 Access Token)
    var token = httpClient.getOAuth2Token( oauth2 );
    apiRequest = apiRequest.bearer( token );
    
    // preparing for API Request (Path parameters)
    var apiUri = "https://www.googleapis.com/drive/v3/files/" + fileId + "/copy";
    
    // preparing for API Request (Query parameters)
    if( supportsTeamDrives === "true" ){
      apiRequest = apiRequest.queryParam( "supportsTeamDrives", true );
    } // API default 'false'
    
    // preparing for API Request (JSON Body)
    var requestObj = {};
      requestObj.parents = [];
      requestObj.parents[0] = parent;
      requestObj.name = name;
    apiRequest = apiRequest.body( JSON.stringify( requestObj ), "application/json" );
    
    // POST Request to the API
    var response = apiRequest.post( apiUri ); // HttpResponseWrapper
    var statusCode = response.getStatusCode() + "";
    var accessLog = "";
    accessLog += "---POST request--- " + statusCode + "\n";
    accessLog += response.getResponseAsString() + "\n";
    
    // Retrieve Properties from Response-JSON
    var newFileId = "";
    var newFileMimeType = "";
    if( statusCode == "200" ){
      var responseObj = JSON.parse( response.getResponseAsString() );
      newFileId  = responseObj.id;
      newFileMimeType = responseObj.mimeType;
    }
    
    ////// == ワークフローデータへの代入 / Data Updating ==
    if( dataIdF !== "" ){
      retVal.put( dataIdF, newFileId );
    }
    if( dataIdG !== "" ){
      retVal.put( dataIdG, newFileMimeType );
    }
    if( dataIdX !== "" ){
      retVal.put( dataIdX, accessLog );
    }
    

    • B’: File ID* of the copy source file stored in the Data Item selected at config B
    • C’: Folder ID** of save destination folder stored in Data Item selected at config C
    • D’: File name of generating file stored in the Data Item selected at config D
    • New file of copy of a file whose ID will be B’ will be generated and stored in a folder whose ID is C’
    • File ID of generated file will be stored in the Data Item selected at config F
    • MimeType of generated file will be stored in the Data Item selected at config G
    • The communication log will be stored in the Data Item selected at X
    • You need to register Project at Google API Manager beforehand
    • If there is no specified file ID or folder ID, an error will result
    • * https://drive.google.com/file/d/023W9z6__EXAMPLE__D45EFmY1E/view
    • ** https://drive.google.com/drive/folders/0_example_EXAMPLE_example_dvamc