How to update list item based on check two list fields value and how to write code in powershell

Hi

How to update list item based on check two list fields value

1) how to get the parentid, filenames,docids  where processNo is null

2) if i get 3 documents from one parentid for those how to update processNo


get the parentids where processno is null and loop those list items and check the listitems under 
each parentId and update processNo

here how to implement this logic in powershell

March 31st, 2015 8:42am

Looks like you're needing a consultant. You should really learn PowerShell if you can not afford to pay for one, this will get you started with number 1:

$SPWeb = Get-SPWeb "http://site"
$List = $SPWeb.Lists["List"]
$test = $list.items


foreach ($i in $test)
{
    if($test["COLUMN"] -eq $null)
    {
      
      $a = $i["Document ID"]
      
      $b = $a.substring($a.indexof(",")+1)

      $test | FL -property @{expression={$b};Label="DocumentID"}, Name, Title
       
    }
    
}

 
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 11:23am

hi  ok where to start basic  programming  with  poweshell  object model

here as shown  above  i need  that every paarentid has some documents  and i want to update  those prosessnos which hass null value, this is only  sample data ,actually  in live it has 5000  documents  

ex if parentid 100 has 3 documents  i want to update  processno like 1,2,3

and next parentid 101 has 2 documents  i wnt to update  processno like 1,2 

i need output like this after update

DoucmentID  ParentID    ProcessNo

1000              100          1

1001              100          2

1002              100          3

2000               101         1

2001              101   2

March 31st, 2015 11:59am

Looks like you're needing a consultant. You should really learn PowerShell if you can not afford to pay fo

Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 3:21pm

i created below function but it did not update values properly

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

$webURL = "http://tspmcwfe:91" $listName = "Courts"

Get the SPWeb object and save it to a variable

$web = Get-SPWeb $webURL

$list = $web.Lists[$listName] $items = $list.items

$internal_counter = 1 $flagPID =1 $vPID=0

Go through all items

foreach($item in $items)

{

$vPID=0

$PID = $item["ParentID"] -not $null $Pno = $item["Processno"] -match $null $between = $item["ParentID"] -match $vPID

if($PID -eq $true -and $Pno -eq $true)

{

if($between -eq $true) {

$item["ProcessNo"] = $internal_counter $vPID=$item["ParentID"] } else { $item["ProcessNo"] = $internal_counter

$vPID=$item["ParentID"] }

$internal_counter++

$item.Update()

} }

$web.Dispose()

enter image description here

April 1st, 2015 2:51am

try this

$parentID = ""
$procNo = 0
foreach ($item in $list.Items) {
	if ($parentID -ne $item["ParentID"])
	{
		$procNo = 1
		$parentID = $item["ParentID"]		
		$item["ProcessNo"] = $procNo
		$item.Update()
		continue
	}
	if ($parentID -eq $item["ParentID"])
	{
		$procNo++
		$item["ProcessNo"] = $procNo
		$item.Update()
	}
}

Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 3:47am

Hi Elnur

I tried your code but here one problem is when a ParentID has 3 documents the processNo is updating for every document 1 .

but i need 

parentid  Document  processno

102         xxx1             1

102         xxx2             2

102         xxx3             3

April 1st, 2015 6:51am

try this

[regex]$aa = ""
$Title = ""
$procNo = 0
foreach ($item in $list.Items) {
	if ($Title.Contains($item["ParentID"]) -eq $False)
	{
		$procNo = 1
		$Title = $Title + $item["ParentID"]		
		$item["ProcessNo"] = $procNo
		$item.Update()
		continue
	}
	if ($Title.Contains($item["ParentID"]) -eq $True)
	{
		$aa = $item["ParentID"]
		$procNo = $aa.Matches($Title).count + 1
		$Title = $Title + $item["ParentID"]
		$item["ProcessNo"] = $procNo
		$item.Update()
	}
}

Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 8:11am

$SPWeb = Get-SPWeb "http://site"
$List = $SPWeb.Lists["List"]
$test = $list.items


$getList = $test.GetDataTable() | Group-Object ParentID | ? {$_.count -gt 1} | %{$_.Name}

foreach ($i in $getList)
{

$duplicate = $test | ?{$_["ParentID"] -eq $i}
$increment = 1

foreach($d in $duplicate)
{
$d["ProcessNo"] = $increment++
$d.Update()
}

}

Here you go. You should really have paid someone for this.

Before:

After:

It adds the numbers based on the internal ID of the row so no matter how you "filtered" them you wont be able to change

April 1st, 2015 9:25am

Hi

in our production server the parentid is not so simple as i mentioned before it was very complexids

the solution provided by Elnur not works for this complex ids

@TenPart i also tried your solution but it miss some parentids

here how can i create a function in powershell  and pass ParentId parameter to this function and get no of childItems 

and increment the processno based on this

or better  how can i create a simple console application to update processno?

Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 1:38pm

Is your parentID a GUID?
April 1st, 2015 2:38pm

it is generated automatically from a scan solution code , in production i have to update processno for 2000 documents at once only..

and i want to update those process nos which has null value under its parentid 

instead of write script its better to use console application and c # ?

Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 3:12pm

give this another try

[regex]$aa = ""
$Title = ";"
$procNo = 0
foreach ($item in $list.Items) {
	if ($Title.Contains($item["ParentID"]) -eq $False)
	{
		$procNo = 1
		$Title = $Title + $item["ParentID"] + ";"		
		$item["ProcessNo"] = $procNo
		$item.Update()
		continue
	}
	if ($Title.Contains($item["ParentID"]) -eq $True)
	{
		$aa = $item["ParentID"]
		$procNo = $aa.Matches($Title).count + 1
		$Title = $Title + $item["ParentID"] + ";"
		$item["ProcessNo"] = $procNo
		$item.Update()
	}
}

April 2nd, 2015 12:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics