4

I am working with InfoPath form data that is then submitted to a SharePoint library and properties from the form are promoted to columns on SP. Nearly every field in the form consists of check boxes (True/False). For example

Form:                                      Column in Sharepoint

Estimate                                   
Check box for Small                        Estimate_Small: True OR False
Check box for Medium                       Estimate_Medium:True OR False
Check box for Large                        Estimate_Large: True OR False

Now realizing the error of my ways, I should have designed the form with one multi-choice list box or something to that effect. However, at this point I'm at trying to merge the columns together easily to where the SP columns will be merged into one column listing Small, Medium, and Large.

Does any have any thoughts on how this could be accomplished programmatically?

  • How do you handle the fact that users could answer true for more than one option? – Mike Dec 16 '15 at 18:11
  • Do you want the new column to be Boolean only? Are users always going to select at least 1 value? – Gaurravs Dec 16 '15 at 18:26
0

I'd say one column for each set of small medium and large, etc.. if it works in that manner. I'm a fan of Powershell, so I'd use Powershell for this. Create the choice column first, listing the three options. This is pseudocode:

add-pssnapin microsoft.sharepoint.powershell

$web = get-spweb http://sharepoint/sites/sitecollection/subsite
$list = $web.Lists["List Title"]
$items = $list.Items

for($i=0;$i -lt $items.Count; $i++)
{
    $item = $items[$i]
  if($item["Small"] -eq $true)
  {
    $item["Size"] = "Small"
  }
  if($item["Medium"] -eq $true)
  {
    $item["Size"] = "Medium"
  }
  if($item["Large"] -eq $true)
  {
    $item["Size"] = "Large"
  }

  $item.Update()

}

Then go back and delete the three true false columns, after verifying data integrity.

| improve this answer | |
0

Just an updated answer to Mikes code:

add-pssnapin microsoft.sharepoint.powershell

$web = get-spweb http://sharepoint/sites/sitecollection/subsite
$list = $web.Lists["List Title"]
$items = $list.Items

for($i=0;$i -lt $items.Count; $i++)
{
    $item = $items[$i]
    $choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue;

  if($item["Small"] -eq $true)
  {

    $choicevalues.Add("Small");
  }
  if($item["Medium"] -eq $true)
  {
    $choicevalues.Add("Medium");
  }
  if($item["Large"] -eq $true)
  {
    $choicevalues.Add("Large");        
  }      
$list.Fields["Size"].ParseAndSetValue($item,$choicevalues);   
$item.Update()  
}

This code is designed considering you are using a new multi choice column. So if user has selected single or two or all choices, all will be shown under this one column.

| improve this answer | |
0

Any reason you can't use a Calculated Column in SharePoint?

=if(Estimate_Small,"Small",if(Estimate_Medium,"Medium",if(Estimate_Large,"Large,"Huh?")))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.