Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve a list item value than add plus or minus 1 to the value next update the field w/ new value

Status
Not open for further replies.
Feb 21, 2013
6
US
I am trying retrieve a list item value based on a selection in a multiselection box than add plus or minus 1 to the value than update the field with the new value.

My code works fine by updating the field to a new value where the users selects in the multiselection box. My problem is retieving the old value first and using that in a simple math equation of plus or minus 1. Than I want to update the value with the answer from the math equation.

I am having trouble retrieving the current value for the list item and using that in the math equation. I can update the list item with no problem but it just ovewrites the value.
The way my code works is : it selects all the values in the multiselection box and stores the array in a text box. Next, It splist those values and loops thorugh each value updating each list item where ID = to value in array. If i can just do a plus or minus a value for a qty available instead of overwritng it this would be great

Code:
  XPathNavigator mainDS = MainDataSource.CreateNavigator(); 
            XPathNavigator array = mainDS.SelectSingleNode("/my:myFields/my:array", NamespaceManager);

            
            //connect to SPList to update
            string siteUrl = "[URL unfurl="true"]http://";[/URL]
            ClientContext clientContext = new ClientContext(siteUrl);
           
            List oList = clientContext.Web.Lists.GetByTitle("List NAme");

            
            //retrieve array values
            string csvValues = array.Value;
            Array  splitArray = csvValues.Split(',');
            
            
            //update List
            
            foreach (string splitItem in splitArray)
            {
                ListItem oListItem = oList.GetItemById(splitItem);
            
                //updates item
                //string oldTitle = oListItem["Title"].ToString();
                //oListItem["Title"] = oldTitle + "1"; 
				
                oListItem["QtyAvailable"] = newQtyAvailable;
                oListItem.Update();
                clientContext.ExecuteQuery();
            }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top