Breeze - Get SharePoint AttachmentFiles from List using Expand? -
i using breeze sharepoint online list, support attachments. breeze query, correctly calls expand , can see through browser , fiddler, json returned attachment data in it. however, entities created in breeze javascript don't contain data attachmentfiles. null. sp adapter doesn't support, or defining attachmentfiles , list entities incorrectly. have tried numerous ways define relationship, using complextype , navigation, autogen id , without, coming stumped.
rest request looks this: /_api/web/lists/getbytitle('contacts')/items?$expand=author/id,attachmentfiles&$select=id,authorid,firstname,title,email,author,attachmentfiles ,author/username
attached view of json returned, , current breeze entities mapped.
snippet entities
//attachments addtype({ name: 'attachmentfiles', dataproperties: { serverrelativeurl: { nullable: false }, filename: { nullable: false } } }); // create entity contacts addtype({ name: 'contacts', defaultresourcename: 'getbytitle(\'contacts\')/items', dataproperties: { id: { type: breeze.datatype.int32 }, authorid: { type: breeze.datatype.int32 }, firstname: { nullable: false }, title: { nullable: false }, // last name field in list email: { nullable: false, validators: [breeze.validator.emailaddress()] }, author: { complextypename: "author" } }, // let model.validation add requirereferenceentity validators navigationproperties: { attachmentfiles: { type: 'attachmentfiles', hasmany: true } } }); see json response below
{ "d": { "results": [ { "__metadata": { "id": "388762a5-a565-4033-af90-5a2ea4cb1894", "uri": "https://foo-616175366e015f.sharepoint.com/sites/devsite/breezesp2013sample/_api/web/lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/items(1)", "etag": "\"3\"", "type": "sp.data.contactslistitem" }, "attachmentfiles": { "results": [ { "__metadata": { "id": "https://foo-616175366e015f.sharepoint.com/sites/devsite/breezesp2013sample/_api/web/lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/items(1)/attachmentfiles('8328787dc792224f625c9645a45d01aa.jpg')", "uri": "https://foo-616175366e015f.sharepoint.com/sites/devsite/breezesp2013sample/_api/web/lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/items(1)/attachmentfiles('8328787dc792224f625c9645a45d01aa.jpg')", "type": "sp.attachment" }, "filename": "8328787dc792224f625c9645a45d01aa.jpg", "serverrelativeurl": "/sites/devsite/breezesp2013sample/lists/contacts/attachments/1/8328787dc792224f625c9645a45d01aa.jpg" }, { "__metadata": { "id": "https://foo-616175366e015f.sharepoint.com/sites/devsite/breezesp2013sample/_api/web/lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/items(1)/attachmentfiles('screen shot 2015-04-23 @ 10.28.35 am.png')", "uri": "https://foo-616175366e015f.sharepoint.com/sites/devsite/breezesp2013sample/_api/web/lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/items(1)/attachmentfiles('screen%20shot%202015-04-23%20at%2010.28.35%20am.png')", "type": "sp.attachment" }, "filename": "screen shot 2015-04-23 @ 10.28.35 am.png", "serverrelativeurl": "/sites/devsite/breezesp2013sample/lists/contacts/attachments/1/screen shot 2015-04-23 @ 10.28.35 am.png" } ] }, "author": { "__metadata": { "id": "1fdc1547-d439-42bd-b3aa-b41e92c8ec6f", "type": "sp.data.userinfoitem" }, "username": "user@contoso.com" }, "id": 1, "id": 1, "title": "alanso", "authorid": 1073741823, "firstname": "fernando", "email": "fernando.alonso@ferrari.it" } ] } }
i see problems here ... can cure.
first, i'd call attention "debugging query results" documentation has many tips diagnose what's going on. not of them applicable valuable clues in there.
i'm curious if entitymanager has entities of type "attachmentfiles". rather doubt it. might check.
regardless, 2 observations leap out @ me:
- the
attachmentfilestype not have key property, property uniquely identifies instance of type. everyentitytypemust have @ least 1 key property.metadatahelpercan detect keys convention there no obvious candidate inattachmentfiles. if there 1 (and don't see it), you'll have specify it.
i'm assuming you're using
metadatahelperdefined in breeze labs breeze.metadata-helper.js write metadata rather raw breeze api purpose. looks doing ... , that's thing.
- your
contactstype identifies one-to-many navigationattachmentfilesdoesn't specify foreign key relationship inattachmentfileslink instances ofattachmentfilescontacts. if breeze createdattachmentfilesinstances json payload, not associate them instances ofcontacts
i don't see in data supports notion attachmentfiles entities. seem embedded in contact type.
there way represent that. i'd want confirmation before went down road. maybe can clarify of points raised here before propose next steps.
Comments
Post a Comment