{"_id":"5759f7608b5e3e2000c0d282","version":{"_id":"5668fab608f90021008e8832","__v":19,"project":"5668fab608f90021008e882f","createdAt":"2015-12-10T04:08:22.769Z","releaseDate":"2015-12-10T04:08:22.769Z","categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.18.0","version":"1.18"},"category":{"_id":"569743020b09a41900b2446d","__v":3,"pages":["56975be30b09a41900b24494","56a15cfd470ae00d00c3061f","56e356004dc30f0e0051b3ed"],"project":"5668fab608f90021008e882f","version":"5668fab608f90021008e8832","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-01-14T06:41:06.893Z","from_sync":false,"order":2,"slug":"javascript-sdk","title":"JavaScript SDK"},"parentDoc":null,"project":"5668fab608f90021008e882f","__v":5,"user":"5668fa9755e4b32100935d41","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-09T23:10:24.792Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":11,"body":"`$p(setArrayRequestFields): String[] -> undefined`\n\nIf you uploaded an item metadata that contains array of Strings, then you must specify that field as an Array to get it returned to you as an Array from recommendations. For example, let's say you have a field named `authors` for each articles you are serving.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Register call to get 100 recommendations for widget 'default-widget'.\\n// Apply a simple callback to print out the JSON response.\\n$p('register', {\\n                  max: 100, // Large number requested so you can see our full range of items\\n                  widget: 'default-widget', // name of widget\\n                  callback: function(resp) {\\n                    console.log(JSON.stringify(resp, null, 2));\\n\\t\\t    \\t\\t\\t\\t\\t\\tconsole.log(\\\"// TEST.\\\");\\n                  }\\n               }\\n);\\n$p(\\\"setRequestFields\\\",[\\\"url\\\",\\\"date\\\",\\\"views\\\",\\\"authors\\\"]) // Set request fields\\n$p(\\\"setArrayRequestFields\\\", [\\\"authors\\\"]) // Set array request fields\\n// Execute the registered call.\\n$p('fetch');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\ncode above will return `authors` field as an array of Strings. If an array field isn't declared as an array request field, then first item of the array will be returned.\n\nIf you have run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"setRequestFieldsAON\\\", true)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThen we will return only the items that have all the request fields (set using `setRequestFields`) *and* all the array request fields (set using `setArrayRequestFields`).\n\nIf you want to force us to return some or all of the array request fields for all items, but you do *not* want to use `setRequestFieldsAON` (because there are non-mandatory fields) you can run the following:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"setMandatoryArrayRequestFields\\\",[\\\"list\\\",\\\"of\\\",\\\"mandatory\\\",\\\"array\\\",\\\"request\\\",\\\"fields\\\"]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"psetarrayrequestfields","type":"fn","title":"$p(\"setArrayRequestFields\")"}

$p("setArrayRequestFields")


`$p(setArrayRequestFields): String[] -> undefined` If you uploaded an item metadata that contains array of Strings, then you must specify that field as an Array to get it returned to you as an Array from recommendations. For example, let's say you have a field named `authors` for each articles you are serving. [block:code] { "codes": [ { "code": "// Register call to get 100 recommendations for widget 'default-widget'.\n// Apply a simple callback to print out the JSON response.\n$p('register', {\n max: 100, // Large number requested so you can see our full range of items\n widget: 'default-widget', // name of widget\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n\t\t \t\t\t\t\t\tconsole.log(\"// TEST.\");\n }\n }\n);\n$p(\"setRequestFields\",[\"url\",\"date\",\"views\",\"authors\"]) // Set request fields\n$p(\"setArrayRequestFields\", [\"authors\"]) // Set array request fields\n// Execute the registered call.\n$p('fetch');", "language": "javascript" } ] } [/block] code above will return `authors` field as an array of Strings. If an array field isn't declared as an array request field, then first item of the array will be returned. If you have run: [block:code] { "codes": [ { "code": "$p(\"setRequestFieldsAON\", true)", "language": "javascript" } ] } [/block] Then we will return only the items that have all the request fields (set using `setRequestFields`) *and* all the array request fields (set using `setArrayRequestFields`). If you want to force us to return some or all of the array request fields for all items, but you do *not* want to use `setRequestFieldsAON` (because there are non-mandatory fields) you can run the following: [block:code] { "codes": [ { "code": "$p(\"setMandatoryArrayRequestFields\",[\"list\",\"of\",\"mandatory\",\"array\",\"request\",\"fields\"]);", "language": "javascript" } ] } [/block]