Palantir Foundry:编写TypeScript本体函数处理DataFrame列值移除逻辑
基于Palantir Foundry本体的TypeScript函数实现
需求说明
- 开发基于Palantir Foundry本体的TypeScript编辑函数,输入为本体对象数组(对应DataFrame行)
- 当移除指定行的
level列值时,同步将该行的responsible、description列置为null
示例场景
初始数据包含ID、level、responsible、description字段,当处理ID为B15和H65的行时,移除其level值的同时,需将这两行的responsible和description设为null。
现有代码片段
@OntologyEditFunction() public async deletevaluetable( objectpart: ObjectPartsNew[], ID?: string, level?: string, responsible?: string, description?: string, ): Promise<void> { function deletevaluetable() { var manual; for (var i = 0; i < objectpart.length; i++) { manual=objectpart[i]; var updates = 0; const properties_dict: manualUpdate = { "manual": ID, }; ..... } } }
完善后的代码实现
@OntologyEditFunction() public async deletevaluetable( objectpart: ObjectPartsNew[], targetIds?: string[], // 改为接收需要处理的ID列表,支持批量操作 ): Promise<void> { // 遍历所有本体对象实例 for (const item of objectpart) { // 检查当前对象ID是否在目标处理列表中 if (targetIds?.includes(item.id)) { // 构建更新属性字典:清空指定字段 const updateProps = { level: null, responsible: null, description: null }; // 执行本体对象异步更新 await item.update(updateProps); } } }
代码说明
- 参数优化:将原单个可选
ID参数改为targetIds数组,支持批量处理多个指定ID的行,适配示例场景需求 - 遍历逻辑:用
for...of替代传统for循环,代码更简洁易读 - 更新逻辑:匹配目标ID的对象时,直接构建需置空字段的字典,调用Foundry本体对象的
update方法完成更新 - 异步处理:确保
update操作使用await,符合函数的async声明规范
内容的提问来源于stack exchange,提问作者elokema
相关产品推荐
相关产品推荐

