You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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);
        }
    }
}

代码说明

  1. 参数优化:将原单个可选ID参数改为targetIds数组,支持批量处理多个指定ID的行,适配示例场景需求
  2. 遍历逻辑:用for...of替代传统for循环,代码更简洁易读
  3. 更新逻辑:匹配目标ID的对象时,直接构建需置空字段的字典,调用Foundry本体对象的update方法完成更新
  4. 异步处理:确保update操作使用await,符合函数的async声明规范

内容的提问来源于stack exchange,提问作者elokema

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 05:31:39