Saturday, 16.12.2017, 18:42
| RSS

Engineer M DevelopmentMA

Главная » 2013 » January » 26 » SharePoint on iOS - part 3
SharePoint on iOS - part 3
17:22


The second part here.

How to edit / update / change values of an Item or create / delete an Item?

After the first and second lesson you know how to get Items and Fields of the List. This data helps to edit values of Item through the method UpdateListItems (http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx).
The request schema look like:
NSString *soapMessage = [NSString stringWithFormat:@"\n"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n"
"<soap12:Body>\n"
"<UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">\n"
"<listName>%@</listName>\n"
"<updates>\n"
"%@"
"</updates>\n"
"</UpdateListItems>\n"
"</soap12:Body>\n"
"</soap12:Envelope>\n"
 , idList, batch];


For the node 'listName' you have to set List ID where exist a specific Item. For the node 'updates' need to set a Batch element that contains methods for adding, editing, deleting Items, is written in the XML code (http://msdn.microsoft.com/en-us/library/ms437562.aspx).
The following example code contains three main methods:
<Batch OnError="Continue" ListVersion="1" >
   <Method ID="1" Cmd="Update">
      <Field Name="ID">4<Field>
      <Field Name="Field_Name">Value</Field>
   </Method>
   <Method ID="2" Cmd="Delete">
      <Field Name="ID" >6</Field>
   </Method>
   <Method ID="3" Cmd="New">
      <Field Name="ID">New</Field>
      <Field Name="FSObjType">1</Field>
      <Field Name="BaseName">Name</Field>
   </Method>
</Batch>


The Batch element can contain some 'Method' nodes, each of them has a unique attribute 'ID' and 'Cmd' that define a type processing of data. In the 'Method' node you have to enumerate necessary Fields which you want to use for the data processing. 
- To update an Item you have to define necessary Fields which you want to update, no defined Fields will not have empty value. 
- To delete specific Items you have to declare Fields which describing this Item. 
- To create a new Item you can add necessary Fields with value, no defined Fields will have empty or default values. By the way, you have to define Fields that have the attribute  Required="TRUE". If you don't declare this the server sometimes can return an error about executing. If the request was done then the Item maybe was created with default values or an auto increment ID.

The following Objective-C code collects the batch element:
NSDictionary *dicFields_Values = [NSDictionary dictionaryWithObjectsAndKeys:@"MyName", @"ows_Titel", @"2012-11-26 12:19:51", @"ows_Modified", nil];
NSMutableString *batch = [NSMutableString stringWithString:
@"<Batch OnError=\"Continue\"
ListVersion=\"1\">\n<Method ID=\"1\" Cmd=\"Update\">\n"];
for(NSString *nameField in [dicFields_Values allKeys])
{
        [batch appendFormat:@"<Field Name=\"%@\">%@</Field>\n",
             [
nameField stringByReplacingOccurrencesOfString:@"ows_" withString:@""],
             [
dicFields_Values objectForKey: nameField]];
}
[batch appendString:@"</Method>\n</Batch>\n"];


Some Field's values contain a unique prefix with the format 'ID;#', example: ows_Author='23;#B. Koin' . '23' is ID of the user's Item 'B.Koin' in the 'Users' List, ';#' is separator. For correctly editing these Fields you have to know ID of the necessary User and add this prefix in a value of Field that defined in the Batch code.
Some Field's values contain own ID prefix, example: ows_FileLeafRef='12;#12_.000'. This ID already exist in the Item data:
<z:row ows_Title='Jim' ows_ID='12' ows_ContentType='Contactperson' ows_Modified='2012-11-26 12:19:51' ows_Created='2012-11-15 12:49:36' ows_Author='23;#B. Koin' ows_Editor='2;#MsD admin'  ows__ModerationStatus='0' ows__Level='1' ows_UniqueId='12;#{730D43B9-DC65-4A2E-9D5E-13C89FB1A5F8}' ows_FSObjType='12;#0' ows_MetaInfo='12;#' ows_owshiddenversion='3' ows_FileLeafRef='12;#12_.000' ows_PermMask='0x1b03c4312ef' ows_FileRef='12;#mobile/Lists/Contact/12_.000' />

A value of Field type 'LookupMulti' can contain several unique IDs of Items, that separated with symbols ';#':  ows_Predecessors="3;#Task1111;#2;#New Task" (example below in the 'Updated Item' code). Consequently, you have to check, that Item's values will be correctly written.

For the New created Item you will receive response like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><UpdateListItemsResult><Results><Result ID="1,New"><ErrorCode>0x00000000</ErrorCode><ID /><z:row ows_ContentTypeId="0x010800B99CA6AF77D3644C84E713EB8EEC322D" ows_Title="Kool" ows_Predecessors="" ows_ID="7" ows_ContentType="Task" ows_Modified="2013-01-27 12:44:29" ows_Created="2013-01-27 12:44:29" ows_Author="23;#B. Koin" ows_Editor="23;#B. Koin" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Kool" ows_LinkTitle="Kool" ows_LinkTitle2="Kool" ows_SelectTitle="7" ows_Order="700.000000000000" ows_GUID="{6F454D2F-FC05-4747-948D-7D993EB956E2}" ows_FileRef="7;#mobile/Lists/Task/7_.000" ows_FileDirRef="7;#mobile/Lists/Task" ows_Last_x0020_Modified="7;#2013-01-27 12:44:29" ows_Created_x0020_Date="7;#2013-01-27 12:44:29" ows_FSObjType="7;#0" ows_SortBehavior="7;#0" ows_PermMask="0x1b03c4312ef" ows_FileLeafRef="7;#7_.000" ows_UniqueId="7;#{9D1C0F8A-7FF8-4BC1-BC7F-C7F2941F39D2}" ows_ProgId="7;#" ows_ScopeId="7;#{03DA4457-7941-4BB0-AF56-AF3084E1FC1B}" ows__EditMenuTableStart="7_.000" ows__EditMenuTableStart2="7" ows__EditMenuTableEnd="7" ows_LinkFilenameNoMenu="7_.000" ows_LinkFilename="7_.000" ows_LinkFilename2="7_.000" ows_ServerUrl="/mobile/Lists/Task/7_.000" ows_EncodedAbsUrl="http://sp.server.com/mobile/Lists/Task/7_.000" ows_BaseName="7_" ows_MetaInfo="7;#" ows__Level="1" ows__IsCurrentVersion="1" ows_ItemChildCount="7;#0" ows_FolderChildCount="7;#0" xmlns:z="#RowsetSchema" /></Result></Results></UpdateListItemsResult></UpdateListItemsResponse></soap:Body></soap:Envelope>

For the Updated Item:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><UpdateListItemsResult><Results><Result ID="1,Update" List="{B007AAF4-9DE1-4694-B449-0EA5BF31D2B5}" Version="4"><ErrorCode>0x00000000</ErrorCode><z:row ows_ContentTypeId="0x010800B99CA6AF77D3644C84E713EB8EEC322D" ows_Title="Task1111" ows_Predecessors="3;#Task1111;#2;#New Task" ows_Priority="(2) Standaard" ows_Status="Niet gestart" ows_StartDate="2012-11-09 00:00:00" ows_ID="3" ows_ContentType="Taak" ows_Modified="2013-01-27 13:08:38" ows_Created="2012-11-09 14:18:28" ows_Author="23;#B. Koin" ows_Editor="23;#B. Koin" ows_owshiddenversion="4" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Task1111" ows_LinkTitle="Task1111" ows_LinkTitle2="Task1111" ows_SelectTitle="3" ows_Order="300.000000000000" ows_GUID="{DEB9A96A-6A31-4903-BE7B-111E40801001}" ows_FileRef="3;#mobile/Lists/Task/3_.000" ows_FileDirRef="3;#mobile/Lists/Task" ows_Last_x0020_Modified="3;#2012-11-09 14:18:28" ows_Created_x0020_Date="3;#2012-11-09 14:18:28" ows_FSObjType="3;#0" ows_SortBehavior="3;#0" ows_PermMask="0x1b03c4312ef" ows_FileLeafRef="3;#3_.000" ows_UniqueId="3;#{6B208320-814D-4D00-8E3E-37264F6F6ABB}" ows_ProgId="3;#" ows_ScopeId="3;#{03DA4457-7941-4BB0-AF56-AF3084E1FC1B}" ows__EditMenuTableStart="3_.000" ows__EditMenuTableStart2="3" ows__EditMenuTableEnd="3" ows_LinkFilenameNoMenu="3_.000" ows_LinkFilename="3_.000" ows_LinkFilename2="3_.000" ows_ServerUrl="/mobile/Lists/Task/3_.000" ows_EncodedAbsUrl="http://sp.server.com/mobile/Lists/Task/3_.000" ows_BaseName="3_" ows_MetaInfo="3;#" ows__Level="1" ows__IsCurrentVersion="1" ows_ItemChildCount="3;#0" ows_FolderChildCount="3;#0" xmlns:z="#RowsetSchema" /></Result></Results></UpdateListItemsResult></UpdateListItemsResponse></soap:Body></soap:Envelope>

For the Deleted Item:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><UpdateListItemsResult><Results><Result ID="1,Delete" List="{B007AAF4-9DE1-4694-B449-0EA5BF31D2B5}" Version="2"><ErrorCode>0x00000000</ErrorCode></Result></Results></UpdateListItemsResult></UpdateListItemsResponse></soap:Body></soap:Envelope>

From these responses you can note nodes 'Result' and 'ErrorCode', if the response was successfully executed, then the node 'Result' contains all Fields and values of Item. If failed, then the node 'ErrorCode' contains a string of error.

Thank you.

Категория: Lessons | Просмотров: 3600 | Добавил: admin | Рейтинг: 5.0/1 |
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]
Меню сайта
Разделы новостей
Concept Software [2]
Programs are planned or under construction.
Software [10]
Release Software
Lessons [12]
About Me [1]
Infa about yourself, documents, certificates ...
Documentation [4]
Documentation of projects
Календарь новостей
«  January 2013  »
SuMoTuWeThFrSa
  12345
6789101112
13141516171819
20212223242526
2728293031
Поиск
Друзья сайта
Статистика
Copyright Macarov Anatoli © 2017
Free website builderuCoz