1

I am working in SharePoint 2016. I have a contact details webpart on one of the pages. Id like to change the Contact person information dynamically based on some other information.

Edit Contact details WebPart

This is how the webpart looks like in sharepoint designer

<WpNs0:ContactFieldControl runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{71ADC02E-ED0E-424D-BB6F-44C10CD731C2}" >
<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
  <Title>Contact Details</Title>
  <FrameType>Default</FrameType>
  <Description>Displays details about a contact for this page or site.</Description>
  <IsIncluded>true</IsIncluded>
  <ZoneID>FullPage</ZoneID>
  <PartOrder>6</PartOrder>
  <FrameState>Normal</FrameState>
  <Height>200px</Height>
  <Width>200px</Width>
  <AllowRemove>true</AllowRemove>
  <AllowZoneChange>true</AllowZoneChange>
  <AllowMinimize>true</AllowMinimize>
  <AllowConnect>true</AllowConnect>
  <AllowEdit>true</AllowEdit>
  <AllowHide>true</AllowHide>
  <IsVisible>true</IsVisible>
  <DetailLink />
  <HelpLink />
  <HelpMode>Modeless</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
  <PartImageLarge>/_layouts/images/wp_pers.gif</PartImageLarge>
  <IsIncludedFilter />
  <ExportControlledProperties>true</ExportControlledProperties>
  <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
  <ID>g_71adc02e_ed0e_424d_bb6f_44c10cd731c2</ID>
  <CacheTimeout xmlns="urn:schemas-microsoft-com:sharepoint:CacheableWebPart">600</CacheTimeout>
  **<ContactLoginName xmlns="urn:schemas-microsoft-com:contactfieldcontrol">i:0#.w|domain\Contact.Name</ContactLoginName>**
</WebPart>
</WpNs0:ContactFieldControl>
1

You could update web part property by JSOM.

Reference MSDN

var siteUrl = '/sites/MySiteCollection';
var serverRelativeUrl = '/sites/MySiteCollection/Default.aspx';

function updateWebPartTitle() {

    this.clientContext = new SP.ClientContext(siteUrl);
    var oFile = clientContext.get_web().getFileByServerRelativeUrl(serverRelativeUrl);

    var limitedWebPartManager = oFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
    this.collWebPart = limitedWebPartManager.get_webParts();

    clientContext.load(collWebPart);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.changeTitle), Function.createDelegate(this, this.onQueryFailed));
}

function changeTitle() {

    if (!collWebPart.get_count()) {
        alert('No Web Parts on this page.');
    }

    var oWebPartDefinition = collWebPart.get_item(2);
    this.oWebPart = oWebPartDefinition.get_webPart();
    oWebPart.set_title('My New Web Part Title');

    oWebPartDefinition.saveWebPartChanges();

    clientContext.load(oWebPart, 'TitleUrl');

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    alert('Title changed for Web Part: ' + this.oWebPart.get_titleUrl());
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • thanks for the link! but i couldn't change the contact name property. – sam Jan 10 '18 at 1:21

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.