在App Maker上创建记录到另一个表

时间:2019-08-23 10:30:53

标签: google-app-maker

我在GCP上有两个表,它们是:

表1:Invoice_Stat:   发票编号(PK)   Invoice_Number字符串   EmailStatus字符串   PaidStatus字符串

表2:项目   身份证号码(PK)   Client_Name字符串   服务字符串   案例数   范围编号   主题字符串   开始日期   临时日期   最后日期   Statusx字符串   CA字符串   POC字符串   Client_Ref字符串   帐单字符串   开票   Invoice_stat_fk

它一对一连接。

流程的流程是: 1.工作人员插入新记录作为新案件。发票尚未创建,案件状态仍处于打开状态。案件处理完毕后,财务人员将单击PREINVOICE按钮,以在Invoice_Stat表上创建发票记录。

  1. 新的Invoice_stat记录仅用于创建invoice_id和invoice_number(应自动创建,格式为2xxxxxxx)。 EmailStatus将设置为“已发送”,因为此按钮还会将发票的电子邮件确认发送给其他员工。并将PaidStatus设置为“否”。在我们收到付款后,PayStatus将由财务人员手动更改为“是”。

按钮脚本:

var to = "anyone@domain.com";
var subject = "Prepare Invoice : " + widget.datasource.item.Client_Name;
var msg = "Please Prepare Invoice for " + "\n\nClient Name : " + 
widget.datasource.item.Client_Name + "\n\nService : " + 
widget.datasource.item.Service + "\n\nCase : " + 
widget.datasource.item.Subjects + "\n\nScope :" + widget.datasource.item.Scope + "\n\nSubject : " + widget.datasource.item.Subjects + "\n\nStart :" + widget.datasource.item.Start + "\n\nInterim : " + widget.datasource.item.Interim + "\n\nStatus :" + widget.datasource.item.Statusx + "\n\nCA : " + widget.datasource.item.Client_Ref + "\n\nBilling : " + widget.datasource.item.Billing + "\n\nFee VS : " + widget.datasource.item.Fee_VS + "\n\nFee VI" + widget.datasource.item.Fee_VI + "\n\nNotes : " + widget.datasource.item.Notes + "\n\nPrep Invoice : " + widget.datasource.item.Prep_Invoice + "\n\nInvoiced : " + widget.datasource.item.Prep_Invoice + "\n\nInvoice Number : " + widget.datasource.item.Invoice_Number;

SendEmail(to, subject, msg);
onCreateCaseStatusClick();

Clinet脚本:

function  clearEmailForm(){
}

function SendEmail(To, Subject, Msg, item){
var status = "sending";
google.script.run.withSuccessHandler(function(result) {
status.text = 'Email sent...';


clearEmailForm();
 })
 .SendEmail(To, Subject, Msg);  
}

function onCreateCaseStatusClick() {
var datasource = app.datasources.Invoice_stat;
google.script.run.withSuccessHandler(function(Invoice_id) {

 // When created, redisplay todo lists.
 datasource.load(function() {

  // When reloaded, select new todo list.
  datasource.selectKey(Invoice_id);
});
}).createCaseStatusWithItem();
}

服务器脚本:

function SendEmail(to, subject, msg) {
MailApp.sendEmail(to, subject , msg);
EmailStatus = "Yes";
  }

function createCaseStatusWithItem() {
// Automatically case number for the user.
var lock = LockService.getScriptLock();
lock.waitLock(10000);
var query = app.models.Invoice_stat.newQuery();
var Invoice_stat = query.run();
var allInvoice_stat = app.models.Invoice_stat.newRecord();
var newInvoice_Number = Invoice_stat.length + 1;
Invoice_stat.EmailStatus = "No";
Invoice_stat.PaidStatus = "No";
app.saveRecords([Invoice_id]);
lock.releaseLock();

// Create first todo item for user convenience.
var todoItem = app.models.Invoice_stat.newRecord();
Invoice_stat.Inovice_Number = '1000000';
app.saveRecords([Invoice_id]);
return Invoice_stat.Invoice_id;
}

我以以下示例为例: https://developers.google.com/appmaker/scripting/overview

结果扩展: 1.它已经发送了电子邮件发票通知。很好。 2它不会在Invoice_stat上创建新记录。

请查看我上面的代码。有没有更简单的方法来更新或插入Invoice_stat表?

还有一个问题。

关于案例详细信息,如果已创建,则有有关发票编号的信息。

但是如果未创建,它将显示空符号,该怎么做?

谢谢

0 个答案:

没有答案