2017-10-16 35 views
1

我建設具有以下數據模型文檔管理應用程序:設置/修改紀錄協會與客戶端腳本

  • Doc_Metadata - Approval_Requests - WorkflowStage - 審批 - 評

我試圖使用文檔審批工作流模板作爲起點,並將Doc_Metadata父項與「請求」模型相關聯,以便每個審批請求都與(擁有b y)父元數據記錄。

我已經得到它的工作從開始到結束沒有拋出任何錯誤,但無論我做什麼我都無法獲得元數據 - 請求關係來保存。

我已經爲下面的添加請求頁面發佈了我的客戶端腳本,並且還附加了我的應用程序的zip,以防有人想要查看更多細節。

任何和所有的建議都令人難以置信的讚賞,我喜歡appmaker的想法,但一直在努力理解關係與他們傳統上在SQL中如何處理。

/** 
* @fileoverview Client script functions for AddRequest page. 
*/ 


/** 
* Navigates user to the add request page and sets page URL parameters. 
* @param {string=} metadataKey - optional metadata with this key will be used 
*  as default for the new approval request. 
*/ 
function gotoAddRequestPage(metadataKey) { 
    var params = { 
    metadataKey: metadataKey 
    }; 
// DEBUG 
    console.log(params.metadataKey); 
    console.log(metadataKey); 

    gotoPage(app.pages.AddRequest, params); 
} 


/** 
* Creates a new request and redirects user to the edit screen afterwards. 
* @param {Widget} submitButton - button that triggers the action. 
*/ 
function createRequest(submitButton) { 
    var addRequestPage = submitButton.root; 

    if (addRequestPage.validate()) { 
    submitButton.enabled = false; 


    submitButton.datasource.saveChanges({ 
     success: function() { 
     submitButton.enabled = true; 

    //DEBUG 
     console.log("requestId:" + submitButton.datasource.item._key); 

     goToRequestDetailsPage(submitButton.datasource.item._key); 
     }, 
     failure: function(error) { 
     submitButton.enabled = true; 
     } 
    }); 
    } 
} 



/** 
* Creates a new request and redirects user to the edit screen afterwards. 
* @param {Widget} cancelButton - button that triggers the action. 
*/ 
function cancelCreateRequest(cancelButton) { 
    cancelButton.datasource.clearChanges(); 
    app.showPage(app.pages.Main); 
} 

function onRequestCreate() { 
    google.script.url.getLocation(function(location) { 
    var metadataKey = location.parameter.metadataKey; 
    var props = { 
    metadataKey: metadataKey 
    }; 
    var allMetadataDs = app.datasources.AllMetadata; 
    var metadataDs = allMetadataDs.item; 
    var requestDs = app.datasources.RequestsByKey; 

    //DERBUG// 
    console.log("metadataKey: " + metadataKey); 

    var newRequest = requestDs.createItem(); 
    newRequest.Metadata = metadataDs; 

    var requests = metadataDs.Request; 

    requests.push(newRequest); 
    }); 
} 

回答

1

努力理解關係與它們是如何在SQL

傳統處理

你可以配置你的應用程序使用雲SQL數據庫:https://developers.google.com/appmaker/models/cloudsql

我不能得到的元數據 - 要求關係保存

這是一個應該工作的片段(假設你在自動保存模式下使用數據源)。

var allMetadataDs = app.datasources.AllMetadata; 

// metadata record that you need should be selected at this point of time 
var metadata = allMetadataDs.item; 
var requestDs = app.datasources.RequestsByKey.modes.create; 
var requestDraft = requestDs.item; 

// This line should create relation between draft request record and 
// existing Metadata record. 
requestDraft.Metadata = metadata; 

// send your draft to server to save 
requestDs.createItem(function(newRecord) { 
    // log persisted request record asynchronously 
    console.log(newRecord); 
}); 

順便說一下,如果您向元數據項添加一個下拉菜單到請求創建表單,您的生活將變得更加輕鬆。