【问题标题】:Podio api - how to set category field when create itemPodio api - 创建项目时如何设置类别字段
【发布时间】:2017-12-10 21:38:40
【问题描述】:

我正在使用 php 包装器,尝试创建一个项目,一切正常,项目正在创建,但我无法更改状态,尝试了不同的方式,但找不到正确的方式。

需要将状态更改为“已关闭”-http://prntscr.com/fsrwc3

代码无效:

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();
$get_item = PodioItem::get_basic($item->item_id);
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();

创建项目后(new PodioItem... 之后),如果我在此代码之后获得字段(仅获得 $item->fieldsPodioItem::get_basic...),我可以看到正确的状态,仅在代码中,仅在创建项目后立即,但是如果我在另一个代码中得到这个项目(只是PodioItem::get_basic...)我会看到默认值,所以代码不会改变状态,看起来我只是看到了一些缓存。

如果我在一个脚本上创建项目:

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();

然后,在另一个脚本更新字段中,它将发生变化:

$get_item = PodioItem::get_basic('639637317');
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();

更新-调试信息:

通过测试代码获取日志 -

PodioItem::create($app_id, ['fields' => ['status'=>[13], 'category'=>[3], 'contract-type'=>[4]]]);

(创建物品的简单变体,有类似new PodioItem...的问题)

所有字段都有类别类型,但是:

status - 具有内联显示类型 - 不要更改

category - 有下拉显示类型 - 正在改变

contract-type - 有下拉显示类型 - 正在改变

日志:

2017-07-08 11:07:22 200 POST /item/app/12152727/
2017-07-08 11:07:22 Request body: {"fields":{"status":[8],"category":[3],"contract-type":[4]}}
2017-07-08 11:07:22 Reponse: {
"presence": {
    "ref_type": "item",
    "ref_id": 641331142,
    "user_id": 4194774,
    "signature": "c165b85090e6ad28e74ae4baf93ee56113f88bc9"
},
"app": {
    "status": "active",
    "sharefile_vault_url": null,
    "name": "Projects",
    "default_view_id": null,
    "url_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
    "icon_id": 378,
    "link_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
    "app_id": 12152727,
    "current_revision": 141,
    "item_name": "Project",
    "link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
    "url": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
    "url_label": "projects",
    "config": {
        "item_name": "Project",
        "icon_id": 378,
        "type": "standard",
        "name": "Projects",
        "icon": "378.png"
    },
    "space_id": 3466816,
    "icon": "378.png"
},
"created_on": "2017-07-10 15:31:16",
"last_event_on": "2017-07-10 15:31:16",
"linked_account_data": null,
"sharefile_vault_folder_id": null,
"app_item_id_formatted": "3988",
"recurrence": null,
"title": "ACSC",
"participants": {},
"created_by": {
    "user_id": 4194774,
    "name": "Anton Mikhailov",
    "url": "https:\/\/podio.com\/users\/4194774",
    "type": "user",
    "image": null,
    "avatar_type": "file",
    "avatar": null,
    "id": 4194774,
    "avatar_id": null,
    "last_seen_on": "2017-07-10 15:31:15"
},
"priority": 641331142.0,
"created_via": {
    "url": null,
    "auth_client_id": 25162,
    "display": true,
    "name": "importer",
    "id": 25162
},
"subscribed_count": 1,
"reminder": null,
"ref": null,
"revision": 0,
"app_item_id": 3988,
"link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/3988",
"item_id": 641331142,
"sharefile_vault_url": null,
"rights": ["subscribe", "grant", "add_conversation", "rate", "update", "delete", "add_file", "grant_view", "view", "comment", "add_task"],
"fields": [{
    "status": "active",
    "type": "category",
    "field_id": 93352415,
    "label": "Division",
    "values": [{
        "value": {
            "status": "active",
            "text": "ACSC",
            "id": 3,
            "color": "D2E4EB"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Division",
        "visible": true,
        "delta": 5,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "active",
                "text": "ACSE",
                "id": 1,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "ACSB",
                "id": 2,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "ACSC",
                "id": 3,
                "color": "D2E4EB"
            }],
            "display": "dropdown"
        }
    },
    "external_id": "category"
}, {
    "status": "active",
    "type": "category",
    "field_id": 148215928,
    "label": "Contract Type",
    "values": [{
        "value": {
            "status": "active",
            "text": "No Contract",
            "id": 4,
            "color": "DDDDDD"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Contract Type",
        "visible": true,
        "delta": 7,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "active",
                "text": "PO \/ Purchase \/ T&M",
                "id": 1,
                "color": "FFD5C2"
            }, {
                "status": "active",
                "text": "Original Contract",
                "id": 2,
                "color": "D2E4EB"
            }, {
                "status": "active",
                "text": "Service Rider",
                "id": 3,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "No Contract",
                "id": 4,
                "color": "DDDDDD"
            }],
            "display": "dropdown"
        }
    },
    "external_id": "contract-type"
}, {
    "status": "active",
    "type": "category",
    "field_id": 93034840,
    "label": "Instal Status",
    "values": [{
        "value": {
            "status": "active",
            "text": "Closed",
            "id": 13,
            "color": "E1D8ED"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Instal Status",
        "visible": true,
        "delta": 13,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "deleted",
                "text": "To Be Reviewed",
                "id": 2,
                "color": "F7F0C5"
            }, {
                "status": "deleted",
                "text": "ACS Accounting Review",
                "id": 5,
                "color": "FFD5C2"
            }, {
                "status": "deleted",
                "text": "Ignite Setup",
                "id": 10,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "To Be Scheduled",
                "id": 8,
                "color": "D2E4EB"
            }, {
                "status": "active",
                "text": "In Progress",
                "id": 6,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "Warranty",
                "id": 11,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "Complete",
                "id": 3,
                "color": "D1F3EC"
            }, {
                "status": "deleted",
                "text": "Closed",
                "id": 7,
                "color": "DDDDDD"
            }, {
                "status": "active",
                "text": "Cancelled",
                "id": 9,
                "color": "DDDDDD"
            }, {
                "status": "deleted",
                "text": "VA in Progress",
                "id": 4,
                "color": "E1D8ED"
            }, {
                "status": "deleted",
                "text": "Submitted",
                "id": 1,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "On Hold",
                "id": 12,
                "color": "F7D1D0"
            }, {
                "status": "active",
                "text": "Closed",
                "id": 13,
                "color": "E1D8ED"
            }],
            "display": "inline"
        }
    },
    "external_id": "status"
}],
"initial_revision": {
    "item_revision_id": 1664054437,
    "created_via": {
        "url": null,
        "auth_client_id": 25162,
        "display": true,
        "name": "importer",
        "id": 25162
    },
    "created_by": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "created_on": "2017-07-10 15:31:16",
    "user": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "type": "creation",
    "revision": 0
},
"current_revision": {
    "item_revision_id": 1664054437,
    "created_via": {
        "url": null,
        "auth_client_id": 25162,
        "display": true,
        "name": "importer",
        "id": 25162
    },
    "created_by": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "created_on": "2017-07-10 15:31:16",
    "user": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "type": "creation",
    "revision": 0
},
"linked_account_id": null,
"push": {
    "timestamp": 1499700676,
    "expires_in": 21600,
    "channel": "\/item\/641331142",
    "signature": "b8a816ff367da6bc730071c875ca3fdca2d2c344"
},
"external_id": null
}

【问题讨论】:

    标签: php podio


    【解决方案1】:

    你试过http://podio.github.io/podio-php/fields/#category-field吗?

    设定值
    使用 option_id 设置单个值。你也可以 用 add_value() 添加一个值

    $item = PodioItem::get_basic(123);
    $field_id = 'category';
    
    // Set value to a single option
    $item->fields[$field_id]->values = 4; // option_id=4
    
    // Add value to existing selection
    $item->fields[$field_id]->add_value(4); // option_id=4
    

    使用数组设置多个值

    $item = PodioItem::get_basic(123);
    $field_id = 'category';
    $item->fields[$field_id]->values = array(4,5,6); // option_ids: 4, 5 and 6
    

    创建具有值的项目:

    $fields = new PodioItemFieldCollection([
        new PodioCategoryItemField(['external_id'=>'status', 'values'=>array(13)]),
    ]);
    $item = new PodioItem([
        'app' => new PodioApp($app_id),
        'fields' => $fields
    ]);
    $item->save();
    

    【讨论】:

    • 它只有在重新启动脚本后才能工作,当我创建一个项目并立即设置值(通过你的方法或我的方法)时,它不起作用。如果我只是获取现有项目并更改状态,它就可以工作。我需要在创建项目时设置状态,在同一个会话中,这将是最好的方式。
    • 您能否创建 2 个示例并解释他们哪些是有效的,哪些是无效的?还请包含您可以从 Podio UI 中看到的值。
    • 更新问题
    • 更新的答案:诀窍是 'values'=>13 应该是 'values'=>array(13) (顺便说一句,你的问题仍然很难理解,你会重写它吗?只保留 2 段代码来解释什么是有效的和什么不是)
    • 我看到源代码和 'values'=>13 和 'values'=>array(13) 具有相同的效果,并在请求中发送相同的数据 - "fields":{"status":[13]},所以,它同样不行
    猜你喜欢
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多