如何获得Zapier MySQL“更新行”以使用Null值更新行中的值?

时间:2019-01-29 05:04:21

标签: python mysql null zapier

我创建了一个Zapier Zap,用于将数据从SmartSheet填充到MySQL数据库。我将其分支,因此如果该行在MySQL中尚不存在,则会创建一个新行。这部分工作正常。 在我的第二个分支中,如果该行已经存在,那么该行中的数据将用SmartSheet行中的新数据进行更新。当现有数据替换为新数据时,Zap可以正常工作。例如。有关现有MySQL行的示例:

+--------+---------------+--------------------+
| row_id | email_comment | smartsheet_orig_id |
+--------+---------------+--------------------+
|    895 | easy          |  6876364645150921  |
+--------+---------------+--------------------+ 

在SmartSheet中,如果用户用另一条替换注释,则MySQL数据已成功更新,例如:

+--------+---------------+--------------------+
| row_id | email_comment | smartsheet_orig_id |
+--------+---------------+--------------------+
|    895 |  difficult    |  6876364645150921  |
+--------+---------------+--------------------+ 

但是,如果用户已在SmartSheet中删除了注释并且未将其替换为另一个注释,则将该注释保留为空,则不会从相应的MySQL记录中删除数据,例如:

+--------+---------------+--------------------+
| row_id | email_comment | smartsheet_orig_id |
+--------+---------------+--------------------+
|    895 |  difficult    |  6876364645150921  |
+--------+---------------+--------------------+ 

在这种情况下,我需要MySQL记录是:

+--------+---------------+--------------------+
| row_id | email_comment | smartsheet_orig_id |
+--------+---------------+--------------------+
|    895 |               |  6876364645150921  |
+--------+---------------+--------------------+ 

经过大量测试,并与Zapier支持进行对话,看来问题是从Zapier Code输出步骤中删除了Null值。因此,以上情况是对我期望发生的事情的总结:

  

Zapier代码步骤:email_comment =空-> MySQL更新行步骤:email_comment =空

但是在代码步骤的输出中,我的emai_comment的Null值被剥离,因此MySQL Update Row Zap步骤将记录解释为不需要更新,因为没有更改,并保留了旧值。

我尝试在代码中传递空字符串“”而不是Null,但得到的结果完全相同。我能看到的唯一方法是传递一些经验字符,然后在“更新行”步骤中,将其替换为Null以存储在记录中,但是我看不到在Zapier中这样做的方法。

我在Google和Here上搜索了其他正在努力解决此问题的人,但已将其完全空白。我一直在使用的搜索字符串是[Zapier]删除数据,[Zapier]删除数据和[Zapier]空。这些搜索的结果似乎都没有解决我遇到的问题。

这是我用来从SmartSheet收集输入的Python代码:

#for a non existent input store an empty value
def gather_vals(inp):
    return input_data.get(inp, emptyInput)

def pull_inputs(inputs, vinputs):
    for key, value in zip(vinputs,inputs):
        v = gather_vals(value)
        d_inputs.update( {key:v})

x_vinputs = ['input_equipment', 'input_from', 'input_to', 'input_description', 'input_contractor', 'input_booked', 'input_confirmed', 'input_job_no', 'input_complete', 'input_est_val', 'input_inv_val', 'input_inv_no', 'input_book', 'input_update', 'input_comments_email']
x_inputs = ['equipment', 'from', 'to', 'description', 'contractor', 'booked', 'confirmed', 'job_no', 'complete', 'est_val', 'inv_val', 'inv_no', 'book', 'update', 'comments_email']

# Gather rest of inputs
emptyInput = None
d_inputs = {}
#gather pick-up/delivery date/time input data
pull_inputs(x_inputs, x_vinputs)
results.update(d_inputs)

return results

代码似乎可以正常工作,不会返回任何错误,并且在SmartSheet中更新了实际值后,在MySQL中对其进行了更新,但是在删除注释时,旧值保留在了MySQL中。

我希望有人可以建议我遵循。

这是Zap流程:

Zap flow

Zapier支持告诉我问题在于,Null被剥去了红色圆圈的Python代码步骤的输出。空值需要流到“更新行”步骤。

在“更新行”步骤中手动输入NULLNullnull会导致将字符串发送给MySQL。参见MySQL Workbench的记录:

enter image description here enter image description here enter image description here

发送空字符串会导致带有引号的字符串发送到MySQL:

enter image description here

看来Zapier步骤只会将字符串发送到MySQL,所以我想这是代码步骤从输出中剥离NULL s的争论所在。

0 个答案:

没有答案