2017-10-16 100 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); 
}); 

顺便说一下,如果您向元数据项添加一个下拉菜单到请求创建表单,您的生活将变得更加轻松。