再次运行脚本时,使系统生成的UUID更改
我有这个为项目生成UUID的脚本。当脚本运行时,我不想替换已经存在的UUID。我需要在此脚本中添加什么,以防止现有的UUID再生?如果单元格中包含数据,则不会设置值的IF语句?现在,此代码将用新的代码覆盖现有的UUID。我正在使用vookup中的uuid,所以我不能让现有的变化。 谢谢。
function generateInviteIds() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const ws = ss.getActiveSheet()
const lr = ws.getRange(ws.getMaxRows(), 6).getNextDataCell(SpreadsheetApp.Direction.UP).getRow()
const idRange = ws.getRange(1, 3, lr, 1).getValues()
//console.log(nr)
//console.log(lr)
//console.log(idRange)
const inviteIds = []
for (let i = 1; i < lr; i++) {
const uid = Utilities.getUuid()
inviteIds.push([uid])
}
ws.getRange(2, 3, inviteIds.length, 1).setValues(inviteIds)
}
I have this script that generates UUID's for a project. When the script runs I do not want to replace the UUID's that already exist. What do I need to add to this script to keep the existing UUID's from regenerating? An if statement that will not setvalues if the cell has data in it? Right now this code will overwrite the existing UUID's with new ones. I am using the UUID in a vlookup, so I can't have the existing ones changing.
thank you.
function generateInviteIds() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const ws = ss.getActiveSheet()
const lr = ws.getRange(ws.getMaxRows(), 6).getNextDataCell(SpreadsheetApp.Direction.UP).getRow()
const idRange = ws.getRange(1, 3, lr, 1).getValues()
//console.log(nr)
//console.log(lr)
//console.log(idRange)
const inviteIds = []
for (let i = 1; i < lr; i++) {
const uid = Utilities.getUuid()
inviteIds.push([uid])
}
ws.getRange(2, 3, inviteIds.length, 1).setValues(inviteIds)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
array.map()
,如下:Use
Array.map()
, like this: