(JavaScript API 1.3 for Office) 自定义属性的设置值

(JavaScript API 1.3 for Office) Set Value of Custom Properties

我的客户已决定迁移到 Office 2016,将部分业务流程移植到该客户需要我们提供文档信息面板的替代品,该面板不再可用。 Backstage 文件信息区域被认为对相关用户来说没有足够的用户体验,因此我们正在努力用任务窗格应用程序替换 DIP。

这个例子:https://www.youtube.com/watch?v=LVGqpns0oT8&feature=share 表明这个想法至少在理论上是可行的。我们考虑过购买此应用程序,但找不到足够的信息来购买。

因此我们着手尝试在 DIP 中复制我们需要的功能。看起来我们可以成功设置标准类型的文档属性,例如字符串,看起来像这样:

Word.context.run(function(context){
    var properties = context.document.properties;
    context.load(properties):
    return context.sync().then(function(){
        properties.title = properties.title + " Additional Title Text"; // once the sync goes off, this works.
        return context.sync();
    });    
});

但是,当我们尝试更新文档 属性 时,例如,由 SharePoint 内容类型定义的托管元数据 属性,代理对象中的值加载并保持更改,但它似乎打破了它与实际文档的关系 属性。下面的代码演示:

Word.context.run(function(context){
    var properties = context.document.properties;
    var customProperties = properties.customProperties;
    context.load(properties):
    context.load(customProperties);
    return context.sync().then(function(){
        var managedMetadataProperty = customProperties.getItem('MngdMetadata');
        properties.title = properties.title + " Additional Title Text"; // once the sync goes off, this works.
        context.load(managedMetadataProperty);
        return context.sync().then(function(){
            console.log(managedMetadataProperty.value) // let's say this looks like "10;#Label 1|64d2cd3d-57d4-4c23-9603-866d54ee74f1"
            managedMetadataProperty.value = "11;#Label 2|cc3d57d4-4c23-72d4-3031-238b9100f52g"
            return context.sync();  // now the value in the javascript object for managedMetadataProperty is updated, but the value in the document does not change. 
        });
    });    
});

文档 属性 托管元数据 属性 在 Word UI 中从未更改,更改也不会推送回 SharePoint。假设我们在进行更新后保存并关闭文档,然后重新打开它。 属性 值没有明显变化,但是当我们用 'context.load()' 加载代理对象时,可用的值反映了我们在上次 运行 上所做的更改。

我不清楚为什么会这样。似乎要绕过这个,我需要回拨 SharePoint 来更新相关字段,但我不知道如何指示 Word 使用来自 SharePoint 的新信息进行刷新。

这是一个很好的问题。 自定义属性 API 使您可以访问一些内置属性以及自定义属性。从 API 的角度来看,与 SP 相关的属性不在此类别中。 (在 VBA/VSTO/COM 中也是如此)要访问这些内容,您需要使用 CustomXmlParts 功能。 Here is a good example关于如何在JavascriptAPI.

中使用它

此外,仅供参考,该团队目前正在开发一项功能以再次启用 DIP,我没有具体的日期或承诺,但您可能很快就会再次获得此功能。

你试过customPropertyCollectionObject.add(key, value)吗?

它将替换 customPropertiesCollectionObject 中现有的 kvp。

这是文档customPropertiesCollection