locked
How to update Promoted Links list? RRS feed

  • Question

  • Hi,

    I have deployed a Promoted Links list to my production server. It has happened that the client requested some changes to the items of the list:

    - Change the Launch Behavior to "New Tab"

    - Change the titles.

    What is the easiest method to make these changes? Making changes manually in SharePoint UI is not an option.

    I know I could write a piece of C# code but I'm wondering that maybe PowerShell could do the same job and, at the same time, it would be less hassle to deploy. What are other alternatives?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, July 21, 2016 7:24 PM

Answers

  • Hi,

    Title field is a text field, we can update  like below:

    $item["Title"]="Test";

    LauchBehavior is a choice type field, we can update like below

    $item["LaunchBehavior"]= $splist.Fields["LaunchBehavior"].GetFieldValue("New tab");

    More information about updating choice field value:

    SharePoint SPFieldChoice change selected value Powershell

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Friday, July 22, 2016 9:28 AM
  • Hi,

    Because the order field's internal name is "TileOrder", so we need to update the order field like below:

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]
    foreach ($item in $spList.Items)
    {
    	$item["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    	if ($item["Title"] -eq "Go there") 
        {
            $item["TileOrder"] = 1
            $item["Title"] = "Go here"
        }
    	$item.Update()
    }

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Wednesday, July 27, 2016 7:16 AM
  • Hi ata,

    Here is a working code snippet for your reference, you can change the site collection url and list name to yours to test:

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]
    $spItem = $spList.GetItemById(1)
    $spItem["Title"] = "Test"
    $spItem["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    $spItem.Update()
    

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, July 25, 2016 10:22 AM

All replies

  • Hi,

    Title field is a text field, we can update  like below:

    $item["Title"]="Test";

    LauchBehavior is a choice type field, we can update like below

    $item["LaunchBehavior"]= $splist.Fields["LaunchBehavior"].GetFieldValue("New tab");

    More information about updating choice field value:

    SharePoint SPFieldChoice change selected value Powershell

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Friday, July 22, 2016 9:28 AM
  • Thanks! It looks like you recommend using PowerShell. I'm not familiar with PowerShell.

    Could you post more complete PowerShell code, please? How to obtain $item and $splist?

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, July 22, 2016 1:59 PM
  • Hi Leszek

    If you want to do using UI, check this, very nice explanation.

    http://social.technet.microsoft.com/wiki/contents/articles/26522.everything-about-promoted-links-in-sharepoint-2013-change-size-wrap-view-handle-click-event-using-jquery.aspx

    https://sharepoint.rackspace.com/sharepoint-2013-how-to-create-a-promoted-links-list-app-part-1

    using PowerShell you can get the Web and Site using below.

    Add-PsSnapin Microsoft.SharePoint.PowerShell

    ## SharePoint DLL++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Start

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

    $Site = Get-SPSite http://siteurl

    If you have Web then use below and comment above line

    $web = Get-spweb http://ptcpasaspapp03/sc2/test/engchanges

    $list = $web.lists[‘ListName’]


    KRISHANA KUMAR

    SharePoint Architect

    Mosstechnet-kk.com

     

    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful

    Friday, July 22, 2016 2:30 PM
  • Krishana: I don't want to do that through UI as I pointed out in my original message: "Making changes manually in SharePoint UI is not an option."

    Jerry Zy already answered my question. I just needed to know what the best method of obtaining $item and $splist using PowerShell is.

    I think I found my answer here: http://www.robertkuzma.com/2012/09/get-items-from-sharepoint-list-using-powershell-script/ (Google is the best tool!)

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, July 22, 2016 3:34 PM
  • I'm trying to execute this code but it does not work:

    $sourceWebURL = "http://myserver"
    $sourceListName = "MyList"
    
    $web = Get-SPWeb $sourceWebURL
    $list = $web.Lists[$sourceListName]
    $items = $list.Items
    
    $items | ForEach-Object {
        $_["LaunchBehavior"]= $list.Fields["LaunchBehavior"].GetFieldValue("New tab");
    }

    I get an error:

    You cannot call a method on a null-valued expression.
    At line:2 char:5
    +     $_["LaunchBehavior"]= $list.Fields["LaunchBehavior"].GetFieldValue("New tab" ...
    +
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    What am I doing wrong?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, July 22, 2016 3:58 PM
  • Can you share your complete script, as per the error it is not able to find your list or the field "LaunchBehavior".




    KRISHANA KUMAR

    SharePoint Architect

    Mosstechnet-kk.com

     

    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful

    Friday, July 22, 2016 4:03 PM
  • Well, that is the complete script. I'm using code snippets from the Jerry's post. The $list is fine (I have checked that). It seems it can't find the "LaunchBehavior" field. Why? This is the Promoted Links list.

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, July 22, 2016 5:25 PM
  • OK, it seems I have fixed the error. There was a space missing in "LaunchBehavior". It should read "Launch Behavior". I run the code but it did not have any effect - all list items remained intact.

    Any ideas?

    This is the complete code:

    $sourceWebURL = "http://myserver"
    $sourceListName = "MyList"
    
    $web = Get-SPWeb $sourceWebURL
    $list = $web.Lists[$sourceListName]
    $items = $list.Items
    
    $items | ForEach-Object {
        $_["Launch Behavior"]= $list.Fields["Launch Behavior"].GetFieldValue("New tab");
    }
    

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, July 22, 2016 7:16 PM
  • Hi ata,

    Here is a working code snippet for your reference, you can change the site collection url and list name to yours to test:

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]
    $spItem = $spList.GetItemById(1)
    $spItem["Title"] = "Test"
    $spItem["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    $spItem.Update()
    

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, July 25, 2016 10:22 AM
  • Thanks Jerry. It seems that I forgot to call $item.Update. LOL, simple solutions are the best.

    How could I execute your code in a loop that would iterate over all list items?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, July 25, 2016 6:34 PM
  • Hi Leszek,

    here you go.

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]


     foreach ($spItem in $spList.Items) {
                               
                                    
                                    $spItem["Title"] = "Test"
    $spItem["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    $spItem.Update()
                                
                            }


    KRISHANA KUMAR

    SharePoint Architect

    Mosstechnet-kk.com

     

    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful

    Monday, July 25, 2016 7:42 PM
  • Almost there. This time I get the following error:

    Exception calling "Update" with "0" argument(s): "Save Conflict.
    Your changes conflict with those made concurrently by another user. If you
    want your changes to be applied, click Back in your Web browser, refresh the
    page, and resubmit your changes."
    At line:13 char:5
    +     $item.Update()
    +     ~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SPException

    The error message does not make much sense to me: I'm running a PowerShell script, not a web browser. Also, I'm the only user who is modifying the list.

    The current script looks like that:

    $sourceWebURL = "http://srerver"
    $sourceListName = "Prosrotet List"
    
    $web = Get-SPWeb -Identity $sourceWebURL
    $list = $web.Lists[$sourceListName]
    $items = $list.Items
    
    foreach ($item in $items) {
        $item["Launch Behavior"]= $list.Fields["Launch Behavior"].GetFieldValue("New tab");
    
        if ($item["Title"] -eq "Go there") {
            $item["Title"] = "Go here"
            $item["Order"] = 2
        }
    
        $item.Update()
    }

    Any suggestions?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, July 25, 2016 8:32 PM
  • Hi,

    Is there any workflow associate with the Promoted links list ?

    I tested the code below in my environment which works fine with loops to update list item:

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]
    foreach ($item in $spList.Items)
    {
    	$item["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    	if ($item["Title"] -eq "Go there") 
        {
            $item["Title"] = "Go here"
        }
    	$item.Update()
    }

    I suggest you can create a new list and then test with the code above to check if it works.

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, July 26, 2016 6:06 AM
  • No, I don't have any workflows associated with my list.

    I have run the script today and this time it worked fine. I guess it will remain a mystery why it did not work yesterday.

    Modifying the Title and Launch Behavior attributes is working fine but it turned out the client also needed to change the order of the items. When I tried to change it using:

    $item["Order"] = 1

    ...it did not have any effect.

    What might be wrong?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, July 26, 2016 1:40 PM
  • Hi,

    Because the order field's internal name is "TileOrder", so we need to update the order field like below:

    $spWeb = Get-SPWeb -Identity http://sp/sites/teamsite/ 
    $spList = $spWeb.Lists["promoted links"]
    foreach ($item in $spList.Items)
    {
    	$item["Launch Behavior"]= $spList.Fields["Launch Behavior"].GetFieldValue("New tab")
    	if ($item["Title"] -eq "Go there") 
        {
            $item["TileOrder"] = 1
            $item["Title"] = "Go here"
        }
    	$item.Update()
    }

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Wednesday, July 27, 2016 7:16 AM
  • Hi ata6502,

    Is there anything updates ? If my reply is helpful to your question, please mark it as answer so that it could help others who stuck with the same question in the forum.

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, July 29, 2016 1:34 AM
  • Yes, I confirm this is the answer to my question.

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, August 4, 2016 2:17 PM