将请求放在多个记录上的REST脚本

发布于 2025-01-27 22:43:20 字数 1300 浏览 5 评论 0原文

我有一个REST脚本,目前在单次录像带请求中运行良好。我正在寻找更新脚本,以便它可以支持多记录更新。

当前脚本:

function put(context) {

    // doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'PUT');
    var rec = record.load({
        type: context.recordtype,
        id: context.id
    });

    var values = context.values;
    for (var fldName in values) {
        if (values.hasOwnProperty(fldName)) {
            rec.setValue({
                fieldId: fldName,
                value: values[fldName]
            });
        }
    }

    rec.save({
        ignoreMandatoryFields: true
    });
    rec = record.load({
        type: context.recordtype,
        id: context.id
    });
    return rec; // reloading includes the results of any triggered actions.
}


return {
    post: postProcess,
    put: put
};

工作单记录JSON主体有效载荷的PUT请求:

{
"recordtype": "customrecord_record",
"id": "201",
"values": {
    "custrecord_managementpriority": "3"
}

理想情况下寻找支持此有效负载结构的PUT脚本:(

{
"recordtype": "customrecord_record",
"id": "201",
"values": {
    "custrecord_managementpriority": "3"
}
},
{
    "recordtype": "customrecord_record",
    "id": "204",
    "values": {
        "custrecord_managementpriority": "4"
    }
}

包裹在[]或当然是必要的)。

I have a REST script that's currently working well for single-record PUT requests. I'm looking to update the script such that it can support multi-record updates.

Current Script:

function put(context) {

    // doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'PUT');
    var rec = record.load({
        type: context.recordtype,
        id: context.id
    });

    var values = context.values;
    for (var fldName in values) {
        if (values.hasOwnProperty(fldName)) {
            rec.setValue({
                fieldId: fldName,
                value: values[fldName]
            });
        }
    }

    rec.save({
        ignoreMandatoryFields: true
    });
    rec = record.load({
        type: context.recordtype,
        id: context.id
    });
    return rec; // reloading includes the results of any triggered actions.
}


return {
    post: postProcess,
    put: put
};

Working Single Record JSON body payload for PUT request:

{
"recordtype": "customrecord_record",
"id": "201",
"values": {
    "custrecord_managementpriority": "3"
}

Ideally looking for the PUT script to support this payload structure:

{
"recordtype": "customrecord_record",
"id": "201",
"values": {
    "custrecord_managementpriority": "3"
}
},
{
    "recordtype": "customrecord_record",
    "id": "204",
    "values": {
        "custrecord_managementpriority": "4"
    }
}

(Wrapped in [ ] or however necessary of course).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┈┾☆殇 2025-02-03 22:43:20

已解决。如果其他人遇到此问题,将留下这篇文章。这件作品预先做到了:

var contexts = context;
if(!Array.isArray(contexts)) 
    contexts = [contexts];

var rec;
contexts.forEach((context) => {

Solved. Will leave this post up in case anyone else runs into this issue. This piece upfront did the trick:

var contexts = context;
if(!Array.isArray(contexts)) 
    contexts = [contexts];

var rec;
contexts.forEach((context) => {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文