设置/修改与客户端脚本的记录关联
Setting / Modifying record associations with client script
我正在使用以下数据模型构建文档管理应用程序:
- Doc_Metadata
- Approval_Requests
- 工作流阶段
- 审批人
- 评论
我正在尝试使用文档审批工作流模板作为起点,并将 Doc_Metadata 父级关联到 "Requests" 模型,这样每个审批请求都关联到(拥有)父元数据记录。
我已经让它从头到尾正常工作,没有抛出任何错误,但是,无论我做什么,我都无法获取要保存的元数据 - 请求关系。
我已经为下面的“添加请求”页面发布了我的客户端脚本,还附上了我的应用程序的 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);
});
}
struggling to understand relations versus how they are traditionally handled in SQL
您可以将您的应用配置为使用云 SQL 数据库:https://developers.google.com/appmaker/models/cloudsql
I cannot get the Metadata - Request relation to save
这是一个应该有效的片段(假设您在自动保存模式下使用数据源)。
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);
});
顺便说一下,如果您在请求创建表单中添加包含元数据项的下拉列表,您的生活会变得更轻松。
我正在使用以下数据模型构建文档管理应用程序:
- Doc_Metadata - Approval_Requests - 工作流阶段 - 审批人 - 评论
我正在尝试使用文档审批工作流模板作为起点,并将 Doc_Metadata 父级关联到 "Requests" 模型,这样每个审批请求都关联到(拥有)父元数据记录。
我已经让它从头到尾正常工作,没有抛出任何错误,但是,无论我做什么,我都无法获取要保存的元数据 - 请求关系。
我已经为下面的“添加请求”页面发布了我的客户端脚本,还附上了我的应用程序的 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);
});
}
struggling to understand relations versus how they are traditionally handled in SQL
您可以将您的应用配置为使用云 SQL 数据库:https://developers.google.com/appmaker/models/cloudsql
I cannot get the Metadata - Request relation to save
这是一个应该有效的片段(假设您在自动保存模式下使用数据源)。
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);
});
顺便说一下,如果您在请求创建表单中添加包含元数据项的下拉列表,您的生活会变得更轻松。