ALV object model - List download

H Experts,
I have used ALV object model to list display.
Also i have used class CL_ALV_COLUMNS_TABLE and its method set_long_text to set the column heading.
Now if i execute this report, long text is displayed properly in column heading.
But when i download this report output in spreadsheet, short text is displayed in column heading which is taken from the data element in DDIC.
Example:
I have declaed a column of type ABWTG.
I have set leng text as 'TEST'.
When i execute the report, column heading is displayed "TEST', which is as expected.
But when i download this report in spreadsheet, column heading is displayed as 'NUMBER' in spread sheet. While downloading column heading is taken from the data element for field ABWTG. But i want the long text 'TEST' to be displayed when the report output is downloaded.
Please suggest how to do it.
Regards

Hi,
As per my understanding , it is displaying in excel based on ur ddic_output_length field.
only becoz of that field it will show the same header.
IF u will change the value at run time for this field then u will not get that issue,
I m also searching on the same issue.
Thanks
Rahul

Similar Messages

  • Questions about ALV object model

    Hi,
    for a new report i´m planing to use the "new" ALV object model to create the ALV list. Now I´ve got two questions concerning this topic:
    - is it possible to switch the ALV into the edit mode like it´s possible if  the "old" CL_GUI_ALV_GRID class  
      is used?
    - how I can encolor specific cells?
    I couldn´t find any hints or demo programms for these questions
    Regards,
    Andy

    it is not possible to Edit the ALV using Object Model.
    For coloring...check this code.
    DATA: alv TYPE REF TO cl_salv_table.
    TYPES: BEGIN OF ty_tab,
             carrid TYPE sflight-carrid,
             connid TYPE sflight-connid,
             color  TYPE lvc_t_scol,
           END OF ty_tab.
    DATA: wt_color TYPE  lvc_t_scol,
          wa_color TYPE  lvc_s_scol,
          w_color  TYPE  lvc_s_colo.
    DATA: wa_flight TYPE ty_tab.
    DATA: column_tab TYPE REF TO cl_salv_columns_table,
          column TYPE REF TO cl_salv_column_table.
    DATA: column_ref TYPE   salv_t_column_ref,
          wa LIKE LINE OF column_ref.
    DATA: it_flight TYPE STANDARD TABLE OF ty_tab.
    SELECT carrid connid FROM sflight
    INTO CORRESPONDING FIELDS OF TABLE it_flight
    UP TO 10 ROWS.
    w_color-col = 4.
    w_color-int = 0.
    w_color-inv = 0.
    LOOP AT it_flight INTO wa_flight.
      w_color-col = 4.
      wa_color-fname = 'CARRID'.
      wa_color-color = w_color.
      APPEND wa_color TO wt_color.
      w_color-col = 6.
      wa_color-fname = 'CONNID'.
      wa_color-color = w_color.
      APPEND wa_color TO wt_color.
      wa_flight-color = wt_color.
      MODIFY it_flight FROM wa_flight.
    ENDLOOP.
    cl_salv_table=>factory(
      IMPORTING
        r_salv_table   = alv
      CHANGING
        t_table        = it_flight
    "get all the columns
    column_tab = alv->get_columns( ).
    column_tab->set_color_column( value = 'COLOR' ).
    column_ref = column_tab->get( ).
    "loop each column
    LOOP AT column_ref INTO wa.
      "Conditionally set the column type as key or non key
      IF wa-columnname   = 'CARRID'.
        column ?= wa-r_column.
        column->set_key( abap_true ).
      ENDIF.
    ENDLOOP.
    alv->display( ).

  • ALV Object Model - Merged Cells

    Hi all
       When utilizing ALV Object Model, how do I display cells as merged when they have the same content?
       Can someone help me out?
       Thank you very much!

    Hello Yun
    In dialog cells are merged automatically as soon as you sort the column containing repeated values.
    Thus, when you call method SET_TABLE_FOR_FIRST_DISPLAY you should additionally provide parameter IT_SORT with the appropriate entries.
    For example, you want to sort your ALV list according to COL_A (1st) and COL_B (2nd):
    ls_sort-spos = 1.
    ls_sort-fieldname = 'COL_A'.
    ls_sort-up        = 'X'.  " sort ascending
    append ls_sort to lt_sort.
    ls_sort-spos = 2.
    ls_sort-fieldname = 'COL_B'.
    ls_sort-up        = 'X'.  " sort ascending
    append ls_sort to lt_sort.
    Regards
      Uwe

  • Editable field in ALV Object Model

    Hi Guys,
    I'm using method cl_salv_table=>factory to display an ALV (Object Model) in my report.
    I want to "open up" one field for user entries, in other words make one column of my table editable.
    I assumed to find the respective methods in class cl_salv_table, cl_salv_columns_table or cl_salv_display_settings, so far without getting anywhere.
    I know about the field-catalogue and the method set_ready_for_input in class CL_GUI_ALV_GRID - it's not working once you're in the object model.
    Any ideas how to do that?
    Thank you!
    With best regards,
    Andreas

    Hi Guys,
    I'm using method cl_salv_table=>factory to display an ALV (Object Model) in my report.
    I want to "open up" one field for user entries, in other words make one column of my table editable.
    I assumed to find the respective methods in class cl_salv_table, cl_salv_columns_table or cl_salv_display_settings, so far without getting anywhere.
    I know about the field-catalogue and the method set_ready_for_input in class CL_GUI_ALV_GRID - it's not working once you're in the object model.
    Any ideas how to do that?
    Thank you!
    With best regards,
    Andreas

  • END_OF_PAGE in ALV Object model

    Dear all,
    I am using ALV Object model, but the END_OF_PAGE is not triggering. I have pasted the sample code below. Let me know how to get  END_OF_PAGE  in ALV OM.
    REPORT  ztest_rr.
    DATA : it_sflight TYPE TABLE OF sflight.
    DATA : gr_sflight TYPE REF TO cl_salv_table,
           gr_content TYPE REF TO cl_salv_form_element,
           gr_sorts   TYPE REF TO cl_salv_sorts,
           gr_events  TYPE REF TO cl_salv_events,
           gr_print   TYPE REF TO cl_salv_print.
          CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
          handle_top_of_page FOR EVENT
              top_of_page OF cl_salv_events
              IMPORTING
              page
              table_index
              r_top_of_page,
          handle_end_of_page FOR EVENT
              end_of_page OF cl_salv_events
              IMPORTING
              page
              r_end_of_page.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    DATA : gr_handler TYPE REF TO lcl_eventhandler.
          CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_top_of_page.
        PERFORM create_alv_form_content_top
          USING    page
                   table_index
          CHANGING gr_content.
        r_top_of_page->set_content( gr_content ).
      ENDMETHOD.                    "handle_top_of_page
      METHOD handle_end_of_page.
        PERFORM create_alv_form_content_eop
        USING    page
        CHANGING gr_content.
        r_end_of_page->set_content( gr_content ).
      ENDMETHOD.                    "handle_end_of_page
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    START-OF-SELECTION.
      SELECT *
      FROM sflight
      INTO TABLE it_sflight.
      TRY.
          CALL METHOD cl_salv_table=>factory
            EXPORTING
              list_display   = if_salv_c_bool_sap=>true
       r_container    =
       container_name =
            IMPORTING
              r_salv_table   = gr_sflight
            CHANGING
              t_table        = it_sflight
        CATCH cx_salv_msg .
      ENDTRY.
      CALL METHOD gr_sflight->get_sorts
        RECEIVING
          value = gr_sorts.
      CALL METHOD gr_sorts->set_group_active
        EXPORTING
          value = if_salv_c_bool_sap=>true.
      TRY.
          CALL METHOD gr_sorts->add_sort
            EXPORTING
              columnname = 'CARRID'
       position   =
       sequence   = IF_SALV_C_SORT=>SORT_UP
       subtotal   = IF_SALV_C_BOOL_SAP=>FALSE
               group      = if_salv_c_sort=>group_with_newpage
       obligatory = IF_SALV_C_BOOL_SAP=>FALSE
    receiving
       value      =
        CATCH cx_salv_not_found .
        CATCH cx_salv_existing .
        CATCH cx_salv_data_error .
      ENDTRY.
      CALL METHOD gr_sflight->get_event
        RECEIVING
          value = gr_events.
      CALL METHOD gr_sflight->get_print
        RECEIVING
          value = gr_print.
      CALL METHOD gr_print->set_reserve_lines
        EXPORTING
          value = 5.
      CREATE OBJECT gr_handler.
      SET HANDLER gr_handler->handle_top_of_page FOR gr_events.
      SET HANDLER gr_handler->handle_end_of_page FOR gr_events.
      CALL METHOD gr_sflight->display
    *&      Form  CREATE_ALV_FORM_CONTENT_TOP
          text
         -->P_PAGE  text
         -->P_TABLE_INDEX  text
         <--P_GR_CONTENT  text
    FORM create_alv_form_content_top  USING    l_page
                                               l_table_index
                                      CHANGING lr_content.
      WRITE 'HAI'.
    ENDFORM.                    " CREATE_ALV_FORM_CONTENT_TOP
    *&      Form  CREATE_ALV_FORM_CONTENT_EOP
          text
         -->P_PAGE  text
         <--P_GR_CONTENT  text
    FORM create_alv_form_content_eop  USING    l_page
                                      CHANGING lr_content.
      WRITE 'BYE'.
    ENDFORM.                    " CREATE_ALV_FORM_CONTENT_EOP

    Dear all,
    I am using ALV Object model, but the END_OF_PAGE is not triggering. I have pasted the sample code below. Let me know how to get  END_OF_PAGE  in ALV OM.
    REPORT  ztest_rr.
    DATA : it_sflight TYPE TABLE OF sflight.
    DATA : gr_sflight TYPE REF TO cl_salv_table,
           gr_content TYPE REF TO cl_salv_form_element,
           gr_sorts   TYPE REF TO cl_salv_sorts,
           gr_events  TYPE REF TO cl_salv_events,
           gr_print   TYPE REF TO cl_salv_print.
          CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
          handle_top_of_page FOR EVENT
              top_of_page OF cl_salv_events
              IMPORTING
              page
              table_index
              r_top_of_page,
          handle_end_of_page FOR EVENT
              end_of_page OF cl_salv_events
              IMPORTING
              page
              r_end_of_page.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    DATA : gr_handler TYPE REF TO lcl_eventhandler.
          CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_top_of_page.
        PERFORM create_alv_form_content_top
          USING    page
                   table_index
          CHANGING gr_content.
        r_top_of_page->set_content( gr_content ).
      ENDMETHOD.                    "handle_top_of_page
      METHOD handle_end_of_page.
        PERFORM create_alv_form_content_eop
        USING    page
        CHANGING gr_content.
        r_end_of_page->set_content( gr_content ).
      ENDMETHOD.                    "handle_end_of_page
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    START-OF-SELECTION.
      SELECT *
      FROM sflight
      INTO TABLE it_sflight.
      TRY.
          CALL METHOD cl_salv_table=>factory
            EXPORTING
              list_display   = if_salv_c_bool_sap=>true
       r_container    =
       container_name =
            IMPORTING
              r_salv_table   = gr_sflight
            CHANGING
              t_table        = it_sflight
        CATCH cx_salv_msg .
      ENDTRY.
      CALL METHOD gr_sflight->get_sorts
        RECEIVING
          value = gr_sorts.
      CALL METHOD gr_sorts->set_group_active
        EXPORTING
          value = if_salv_c_bool_sap=>true.
      TRY.
          CALL METHOD gr_sorts->add_sort
            EXPORTING
              columnname = 'CARRID'
       position   =
       sequence   = IF_SALV_C_SORT=>SORT_UP
       subtotal   = IF_SALV_C_BOOL_SAP=>FALSE
               group      = if_salv_c_sort=>group_with_newpage
       obligatory = IF_SALV_C_BOOL_SAP=>FALSE
    receiving
       value      =
        CATCH cx_salv_not_found .
        CATCH cx_salv_existing .
        CATCH cx_salv_data_error .
      ENDTRY.
      CALL METHOD gr_sflight->get_event
        RECEIVING
          value = gr_events.
      CALL METHOD gr_sflight->get_print
        RECEIVING
          value = gr_print.
      CALL METHOD gr_print->set_reserve_lines
        EXPORTING
          value = 5.
      CREATE OBJECT gr_handler.
      SET HANDLER gr_handler->handle_top_of_page FOR gr_events.
      SET HANDLER gr_handler->handle_end_of_page FOR gr_events.
      CALL METHOD gr_sflight->display
    *&      Form  CREATE_ALV_FORM_CONTENT_TOP
          text
         -->P_PAGE  text
         -->P_TABLE_INDEX  text
         <--P_GR_CONTENT  text
    FORM create_alv_form_content_top  USING    l_page
                                               l_table_index
                                      CHANGING lr_content.
      WRITE 'HAI'.
    ENDFORM.                    " CREATE_ALV_FORM_CONTENT_TOP
    *&      Form  CREATE_ALV_FORM_CONTENT_EOP
          text
         -->P_PAGE  text
         <--P_GR_CONTENT  text
    FORM create_alv_form_content_eop  USING    l_page
                                      CHANGING lr_content.
      WRITE 'BYE'.
    ENDFORM.                    " CREATE_ALV_FORM_CONTENT_EOP

  • How do I create a context menu in the new ALV object model (cl_salv_table)?

    Hi,
    Does anyone know how to create a context menu (right click on line or field) in the new ALV object model (class CL_SALV_TABLE)?
    Thanks in advance
    Keld Gregersen
    PS: In the past we could use event CONTEXT_MENU_REQUEST in class CL_GUI_ALV_GRID, so it must be possible

    I don't think there's "any such animal" in the new class. I'm not 100% certain however but the new class is only useful for fairly simple display only type grids.
    There's no edit capability either.
    I'd stick with cl_gui_alv_grid until there's some decent extra functionality in the cl_salv_table class.
    It's fine for quick "bog standard" displays as it doesn't need a field catalog or any screens to be created by the user or developer  - but you pay a price for that in limited fnctionality.
    Cheers
    jimbo

  • ALV  object  model examples

    Dear All
    Can anybody tell me, where will i find the examples for ALV report using object model (two-dimensional table).
    Thanks
    ravi

    Hi Ravindra,
    Transaction DWDM, Under grid controls...
    Also check out all report programs that contain BCALV_GRID*
    BCALV_GRID_DEMO being the simple one..
    CL_GUI_ALV_GRID is the class, you can find some sample programs by doing a where used list on it as well..
    Sri
    Message was edited by: Srikanth Pinnamaneni

  • Alv object model and cl_salv_hierseq_level

    I have used the cl_salv_hierseq_level to enable expand and collapse on an instance of cl_salv_hierseq_table.
    The function to show the detail lines works until the grid table is refreshed from the database.  I have tried using the set_items_expanded method again after the refresh to no avail.
    Can anyone provide information on how to use the class and methods after some grid processing to keep expand and collapse enabled?

    There are no replies to this question; but I have noticed the expand/collapse works after process and refresh now.

  • List all users with full control on a SharePoint 2013 Sub site from SharePoint Object Model in C#

    If I have a sub site URL and a user with Site Admin, can I list all users in that sub site that have Full Control at that level?
    Any C# code sample?

    Still you can do that, just pass the subsites to your code and from their you can find the users dynamically.
    You could also use SPWeb.Users property to get users assigned to a subsite
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.users(v=office.15).aspx
    alternatively you can also use SPWeb.SiteUsers to get all users
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.siteusers(v=office.15).aspx
    other APIs of help-
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.associatedmembergroup(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.associatedownergroup(v=office.15).aspx
    http://sharepoint.stackexchange.com/questions/101671/object-model-list-all-users-with-full-control-on-a-sub-site-in-sharepoint-2013
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • Message in Status Bar while using ALV Objects

    Hi All,
    If we use ALV in objects (Build in class and methods for ALV),is it possible to display a error message using Message statement in Status bar.
    Thanks in advance.

    Hi,
    Yes, it is possible.  You can do it using the ALV Object Model (ALV OO methods) within an event handler method.  For example, the event "added_function of cl_salv_events" can be used and you can add code similar to the following code within the event handler method:
    CASE e_salv_function.
      WHEN 'XYZ'.
        MESSAGE w001(00) WITH 'Message text goes here...'.
    ENDCASE.
    The warning message will either show up as a popup or in the status bar depending on your user settings.  Of course, you can also use other message types (e.g. I, E, S) or other message techniques besides the message statement.
    Best Regards,
    Jamie

  • Trying to use Web LCID property to get the List name in client object Model

    Hi ,
    I am trying to change the "Personal Documents" list NoCrawl property under MySite using SharePoint Client Object Model. As we use  web.Lists.GetByTitle("Personal
    Documents"); method to get the list,but here problem is :for different language List name is in their language.So I tried to use LCID property of the WEB and
    have taken key-value pair (PersonalSiteOnet_List_PersonalDocuments) from the resource file for that language from 14 hive.
    Example:I have selected Spanish language .there are so many LCID for Spanish language but Microsoft has given only one language pack for Spanish.
    Then,My Question is that
    "All LCID for Spanish language are using same Spanish language pack dictionary file OR something else"
     

    Hi,
    According to your post, my understanding is that your requirement is getting list in different language.
    Here are two ways for your reference:
    1. We can use getById method instead, so that we can avoid the language issue.
    2. We can use an array to store the different list name in different language in you JavaScript code, then use the code snippet below to get the list:
    var userLcid =_spPageContextInfo.currentLanguage;
    var localizedStrings = {
    ListName: {
    _1033: "EnglishName",
    _3082: "SpanishName"
    var listName=localizedStrings.ListName["_" + userLcid];
    var list=web.Lists.getByTitle(listName);
    More information:
    http://msdn.microsoft.com/en-us/library/hh670609.aspx
    http://wellytonian.com/2012/11/language-packs-sharepoint-2010/
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How can I get an item and it's attachments from the current list using SP's JavaScript Client Object Model on newform.aspx?

    I only recently learned/read about SharePoint's JavaScript Client Object Model. I'm reading online trying to figure this out but not having much luck.
    On newform.aspx (and dispform.aspx) I want to get the
    current list,
    the last item created, and it's attachments. I now the CAML query I need to get the last item created, but first I have to get the current list and I am not sure how to do that.
    I tried this but it returns null:
    SP.ListOperation.Selection.getSelectedList()

    Hi,
    For your issue, you can get the list name from the new form url and retrieve the list last created item :
    https://social.msdn.microsoft.com/Forums/office/en-US/b90a64f8-2255-41b0-9d91-78335dd4a4cf/get-list-name-from-list-url-through-javascript?forum=sharepointdevelopmentprevious
    http://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Unable to get the SharePoint 2013 List names using Client object model for the input URL

    Please can you help with this issue.
    We are not able to get the SharePoint 2013 List names using Client object model for the input URL.
    What we need is to use default credentials to authenticate user to get only those list which he has access to.
    clientContext.Credentials = Net.CredentialCache.DefaultCredentials
    But in this case we are getting error saying ‘The remote server returned an error: (401) Unauthorized.’
    Instead of passing Default Credentials, if we pass the User credentials using:
    clientContext.Credentials = New Net.NetworkCredential("Administrator", "password", "contoso")
    It authenticates the user and works fine. Since we are developing a web part, it would not be possible to pass the user credentials. Also, the sample source code works perfectly fine on the SharePoint 2010 environment. We need to get the same functionality
    working for SharePoint 2013.
    We are also facing the same issue while authenticating PSI(Project Server Interface) Web services for Project Server 2013.
    Can you please let us know how we can overcome the above issue? Please let us know if you need any further information from our end on the same.
    Sample code is here: http://www.projectsolution.com/Data/Support/MS/SharePointTestApplication.zip
    Regards, PJ Mistry (Email: [email protected] | Web: http://www.projectsolution.co.uk | Blog: EPMGuy.com)

    Hi Mistry,
    I sure that CSOM will authenticate without passing the
    "clientContext.Credentials = Net.CredentialCache.DefaultCredentials" by default. It will take the current login user credentials by default. For more details about the CSOM operations refer the below link.
    http://msdn.microsoft.com/en-us/library/office/fp179912.aspx
    -- Vadivelu B Life with SharePoint

  • How to get list of users who all are having full access in sharepoint site using client object model c#

    Hi,
    I want to fetch the list of users who all are having full access to the sharepoint list using client object model with .Net
    Please let me know if any property for the user object or any other way to get it.
    Thanks in advance.

    Here you are complete code i created from some years it lists all groups and users, you can just add a check in the permissions loop to see if it is equal to Full Control.
    Private void GetData(object obj)
    MyArgs args = obj as MyArgs;
    try
    if (args == null)
    return; // called without parameters or invalid type
    using (ClientContext clientContext = new ClientContext(args.URL))
    // clientContext.AuthenticationMode = ClientAuthenticationMode.;
    NetworkCredential credentials = new NetworkCredential(args.UserName, args.Password, args.Domain);
    clientContext.Credentials = credentials;
    RoleAssignmentCollection roles = clientContext.Web.RoleAssignments;
    ListViewItem lvi;
    ListViewItem.ListViewSubItem lvsi;
    ListViewItem lvigroup;
    ListViewItem.ListViewSubItem lvsigroup;
    clientContext.Load(roles);
    clientContext.ExecuteQuery();
    foreach (RoleAssignment orole in roles)
    clientContext.Load(orole.Member);
    clientContext.ExecuteQuery();
    //name
    //MessageBox.Show(orole.Member.LoginName);
    lvi = new ListViewItem();
    lvi.Text = orole.Member.LoginName;
    lvsi = new ListViewItem.ListViewSubItem();
    lvsi.Text = orole.Member.PrincipalType.ToString();
    lvi.SubItems.Add(lvsi);
    //get the type group or user
    // MessageBox.Show(orole.Member.PrincipalType.ToString());
    if (orole.Member.PrincipalType.ToString() == "SharePointGroup")
    lvigroup = new ListViewItem();
    lvigroup.Text = orole.Member.LoginName;
    // args.GroupsList.Items.Add(lvigroup);
    DoUpdate1(lvigroup);
    Group group = clientContext.Web.SiteGroups.GetById(orole.Member.Id);
    UserCollection collUser = group.Users;
    clientContext.Load(collUser);
    clientContext.ExecuteQuery();
    foreach (User oUser in collUser)
    lvigroup = new ListViewItem();
    lvigroup.Text = "";
    lvsigroup = new ListViewItem.ListViewSubItem();
    lvsigroup.Text = oUser.LoginName;
    lvigroup.SubItems.Add(lvsigroup);
    //args.GroupsList.Items.Add(lvigroup);
    DoUpdate1(lvigroup);
    // MessageBox.Show(oUser.LoginName);
    RoleDefinitionBindingCollection roleDefsbindings = null;
    roleDefsbindings = orole.RoleDefinitionBindings;
    clientContext.Load(roleDefsbindings);
    clientContext.ExecuteQuery();
    //permission level
    lvsi = new ListViewItem.ListViewSubItem();
    string permissionsstr = string.Empty;
    for (int i = 0; i < roleDefsbindings.Count; i++)
    if (i == roleDefsbindings.Count - 1)
    permissionsstr = permissionsstr += roleDefsbindings[i].Name;
    else
    permissionsstr = permissionsstr += roleDefsbindings[i].Name + ", ";
    lvsi.Text = permissionsstr;
    lvi.SubItems.Add(lvsi);
    // args.PermissionsList.Items.Add(lvi);
    DoUpdate2(lvi);
    catch (Exception ex)
    MessageBox.Show(ex.Message);
    finally
    DoUpdate3();
    Kind Regards, John Naguib Technical Consultant/Architect MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation

  • Issue in adding new items to a O365 SharePoint Online List having lookup columns (Client Object Model)

    I have two Lists i.e. Publisher and Products in my SharePoint Online site. They are having the following structures:
    1. Publisher:
    Publisher (Single line of txt)
         A1
         A2
         A3
         A4
         A5
         A6
    2. Products:
    Publisher (lookup to the above column)       
    ProductName (Single line of txt)
         A1                                                                   Apple
         A2                                                                   Samsung
         A3                                                                   Nokia
    And I have an excel file named Products.xlsx in my local machine which has the following data:
    Publisher        ProductName
         A1                   Apple
         A2                   Samsung
         A3                   Nokia
         A4                   Motorola
         A5                   LG
         A6                   HTC
    Now I have written the below client-side (CSOM) code to fetch the data from the Excel and update the corresponding fields in the Products table:
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Web;
    using System.IO;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Client;
    using File =
    Microsoft.SharePoint.Client.File;
    using System.Security;
    namespace ExcelToSP
        public class
    ExcelToSP
            //Main function to get the command line values and invoke the getSPList function to pull SP List data
            public
    static void Main(string[] args)
                //Instantiate Class object
                ExcelToSP p
    = new ExcelToSP();
                try
                    p.LoadExcelData();
    //Exit with Sucess code
    Environment.Exit(0);
                catch
    (Exception ex)
    //Invoke writeErrorLog function to log the exception details
    //p.WriteErrorLog(ex);
            public
    void LoadExcelData()
                try
                string fileName
    = @"E:\Products.xlsx";
                string fileExtension
    = Path.GetExtension(fileName).ToUpper();
                string connectionString
    = "";
                 if
    (fileExtension == ".XLS")
                    connectionString
    = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='"
    + fileName + "'; Extended Properties='Excel 8.0;HDR=YES;'";
                else
    if (fileExtension ==
    ".XLSX")
                    connectionString
    = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='"
    + fileName + "';Extended Properties='Excel 12.0 Xml;HDR=YES;'";
                if
    (!(string.IsNullOrEmpty(connectionString)))
    string[] sheetNames =
    GetExcelSheetNames(connectionString);
    if ((sheetNames !=
    null) &&
    (sheetNames.Length
    > 0))
    DataTable dt = null;
    OleDbConnection con =
    new OleDbConnection(connectionString);
    OleDbDataAdapter da =
    new OleDbDataAdapter("SELECT * FROM ["
    + sheetNames[0]
    + "]", con);
                        dt
    = new DataTable();
                        da.Fill(dt);
    InsertIntoList(dt,"Products");
                catch
    (Exception ex)
    throw ex;
            private
    string[] GetExcelSheetNames(string strConnection)
                var connectionString
    = strConnection;
                String[] excelSheets;
                using
    (var connection =
    new OleDbConnection(connectionString))
                    connection.Open();
    var dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
    null);
    if (dt ==
    null)
    return null;
                    excelSheets
    = new String[dt.Rows.Count];
    int i = 0;
    // Add the sheet name to the string array.
    foreach (DataRow row
    in dt.Rows)
                        excelSheets[i]
    = row["TABLE_NAME"].ToString();
                        i++;
                return excelSheets;
            private
    void InsertIntoList(DataTable listTable,
    string ListName)
                try
    string username = "[email protected]";
    string pwd = "contoso@1234";//this.Dts.Variables["password"].Value.ToString();
    ClientContext clientContext =
    new ClientContext("https://contoso.sharepoint.com/teams/myPOC/");
    SecureString password =
    new SecureString();
    char[] decryptpwd = pwd.ToCharArray();
    foreach (char c
    in decryptpwd)
                        password.AppendChar(c);
                    clientContext.Credentials
    = new SharePointOnlineCredentials(username, password);
                    clientContext.ExecuteQuery();
    //Setting SiteURL Client context
    Web web = clientContext.Web;//
                    clientContext.Load(web);
                    clientContext.ExecuteQuery();
    List lstProductFamily = web.Lists.GetByTitle("Products");
    for (int iRow
    = 0; iRow < listTable.Rows.Count; iRow++)
    ListItemCreationInformation itemCreateInfo =
    new ListItemCreationInformation();
    ListItem newItem = lstProductFamily.AddItem(itemCreateInfo);
    //FieldLookupValue flv = newItem["Publisher"] as FieldLookupValue ;
    //string lkup = flv.LookupValue;
    //int valueid = 0;
    //valueid = flv.LookupId;
                        newItem["Publisher"]
    = Convert.ToString(listTable.Rows[iRow][0]);
                        newItem["ProductName"]
    = Convert.ToString(listTable.Rows[iRow][1]);
                        newItem.Update();
                        clientContext.ExecuteQuery();
                catch
    (Exception ex)
    throw ex;
    But I'm getting the following error on running the above code "Invalid data has been used to update the list item. The field you are trying to update may be read only." 
    Can anybody please help me out?

    Hi,
    According to your description, my understanding is that you want to update data to look up field.
    I have a test about updating look up field using Client Object Model in my environment. lookup field will accept an array to set the field value.
    Here is the code snippet:
    Microsoft.SharePoint.Client.ClientContext ctx = new ClientContext("http://sp2013sps/sites/test/");
    if (ctx != null)
    List list = ctx.Web.Lists.GetByTitle("List3");
    ListItem itemToUpdate = list.GetItemById(1);
    ctx.Load(itemToUpdate);
    ctx.ExecuteQuery();
    FieldLookupValue newLookUpField = new FieldLookupValue();
    newLookUpField.LookupId = 3;
    FieldLookupValue newLookUpField1 = new FieldLookupValue();
    newLookUpField1.LookupId = 4;
    FieldLookupValue[] newarr = { newLookUpField, newLookUpField1 };
    itemToUpdate["lookup"] = newarr;
    itemToUpdate.Update();
    ctx.Load(itemToUpdate);
    ctx.ExecuteQuery();
    Best regards
    Patrick Liang
    TechNet Community Support

Maybe you are looking for

  • An unexpected error occurred while the job was running. (ID 104 Details: The parameter is incorrect (0x80070057))

    We are using DPM Version: 4.1.3465.0 with System Center 2012 Service Pack 1 to back up VMs in our Hyper V Cluster. We have a total of 37 VMs with a combination of 2008r2 servers and 2012 servers. One of our 2012 servers will not backup, and we consis

  • Pricing messages are not appering in WEB UI?

    Hi Team, Please help me on this. In GUI crmd_order->sold to party->product's->item's->condition's. In webui->Account confirmation->create order->item's (add product)->edit the item->Price details assignment block Here i am  createing another pricing

  • Deprecation of JMS topic receival in post 7.0

              Hi,           In chapter 12 of the "Programming WebLogic Web Services" manual of WebLogic 7.0,           I read:           "Receiving Data from a JMS topic is deprecated in this version of WebLogic Server"           Is this realy true (sinc

  • Cisco Aironet 1200

    Cisco Aironet 1200 Firmware 12.3(8)JEB Hello, I want to control client associations when AP load is high. Is there an MIB object that enables/disables client associations? I have searched the supported MIBS, but i could not find anything.

  • Ajax Report Pull from another Page Pagination override

    We are on a time crunch and need to get this application working in a timely manner, any help would greatly be appreciated.. *[History leading up to problem]* We followed the code from this example http://apex.oracle.com/pls/otn/f?p=11933:48:44411421