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

My client has decided to migrate to Office 2016 and porting portions of a business process to that client requires us to offer a replacement to the Document Information Panel, which is no longer available. The Backstage file information area isn't considered a sufficient user experience for the users in question, so we're endeavoring to replace the DIP with a Task Pane app.
This example: https://www.youtube.com/watch?v=LVGqpns0oT8&feature=share shows that the idea is, at least in theory, possible. We considered buying this app but can't find sufficient information to do so.
So we set about attempting to replicate the functionality we need in the DIP. It appears that we can successfully set Document Properties of standard types, such as strings, which looks something like this:
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();
});
});
However, when we try to update an Document Property that's, for example, a Managed Metadata property defined by a SharePoint content type, the value in the proxy object loads and remains changed, but it seems to break its relationship to the actual document property. The code below demonstrates:
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.
});
});
});
The document property Managed Metadata Property never changes in the Word UI, nor does a change push back to the SharePoint. Say we save and close the document after making the update, then re-open it. The Property value has not visibly changed, however when we load the proxy object with 'context.load()', the value that's available reflects the changes we made on last run.
I'm unclear about why this would be. It seems like to circumvent this, I would need to make a call back to SharePoint to update the relevant field, but I don't know how I would instruct Word to refresh with the new information from SharePoint.

That's a great question.
The custom properties API gives you access to some built-in properties as well as custom properties. SP-related properties do NOT follow in this category from the API perspective. (and the same is true in VBA/VSTO/COM) To access those you need to use the CustomXmlParts functionalities. Here is a good example on how to use it in the Javascript API.
Also, FYI, the team is working right now in a feature to enable the DIP again, i don't have concrete dates or commitment, but you might get this functionality again out of the box soon.

Have you tried customPropertyCollectionObject.add(key, value) ?
It will replace existing kvp's in the customPropertiesCollectionObject.
Here is the documentation customPropertiesCollection

Related

How to one-way process html data for the view in CKEditor 5?

In the CKEditor view for authors I need to change links to files so that the session ID of the author gets attached. However in the actual content for normal users the specific user ID is added automatically. Therefore the authors ID must not be saved in the content the author edits with CKEditor, it just has to be there in the view while he edits so that he can see an image for example. On save the 'clean' link without any IDs need to be saved.
In CKEditor 5 there seem to be more possibilities to achieve such a one-way data filtering for example with
Conversions
the Editing Engine generally
the HtmlDataProcessor specifically
However I couldn't find a good example respectively an easy and clean approach to achieve this. (My tries turned out to become quite complicated and didn't work properly...) I'd guess this is a quite common use case so maybe I'm overlooking something. Is there a good solution to this?
Update 1: Example links would be:
"clean link" how it has to be saved but will never work:https://example.com/some-image.png
modified link for specific users in content (and how it has to be modified in ckeditor view for authors as well): https://example.com/some-image.png?sessionId=currentUsersSessionId
Update 2:
While I was working further with CKEditor I came across more things like this which simply are very unpleasant from a developers point of view. And it seems this is by design, since quote from a Contributor 'fredck':
[...] we want to bring the editor out of the "HTML Editor" thing, making it the perfect soluting for "quality content writing".
Implicitly this means, if you are a developer and you have advanced users with advanced use cases (which may be likely the case if you are on Stackoverflow) you are not the target audience and shouldn't use CKEditor in the first place.
You can read more about this for example in the discussion here (also it is about another feature): https://github.com/ckeditor/ckeditor5/issues/592
To modify downloaded links you can write a custom downcast converter, which modifies obtained href.
Here is a working sample which adds the current timestamp to URLs:
https://codepen.io/msamsel/pen/zVMvZN?editors=1010
editor.conversion.for( 'dataDowncast' ).add( dispatcher => {
dispatcher.on(
'attribute:linkHref',
( evt, data, conversionApi ) => {
if ( !conversionApi.consumable.test( data.item, 'attribute:linkHref' ) ) {
return;
}
if ( data.attributeNewValue ) {
data.attributeNewValue += `#time=${ ( new Date() ).getTime() }`;
}
},
{ priority: 'high' }
);
} );
Few words how it works.
There is created listener which reacts on attribute:linkHref changes (it's fired only when data are obtained anyway because it's dataDowncast). Listeners fires with 'high' priority to change URL before the actual Link plugin will create an output. First is checked if the given model element is not consumed, but without consuming it, because we want to preserve native behavior which will process this same element again. The attribute value is extended with a timestamp, what finish this listener. After that, the native behaviour is fired, which has 'normal' priority.
A similar approach was used to implement custom link attributes. More about dispatcher and conversion process might be found here:
https://ckeditor.com/docs/ckeditor5/latest/framework/guides/architecture/editing-engine.html#conversion
https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_conversion_downcastdispatcher-DowncastDispatcher.html

Safe way to store data for button clicks

I am trying to find out what the safest way to store data for use when the user clicks on a button.
I know that you can store data in attributes(either the value attribute or a data- attribute) of the button tag like so:
<button type="button" value="1" data-value="1">Click me!</button>
But the problem with this is that the user(probably really only advanced users) can manipulate the value with firebug or some other app and THEN click the button and send over different data. I fully understand that I need to check the input before I try to do anything with the sent data.
I also found out that I could use jQuery's .data() to attach data to dom elements, which seems a bit more useful. I'm not exactly sure how the data is stored, but I assume its harder to manipulate.
What got me really interested in this question was when I was looking through Soundcloud's code in firebug, I saw that none of the "like" buttons had data attached to the buttons. I tried deleting/manipulating elements/data and the buttons still worked. So it got me thinking that they are probably using a similar process to what jquerys data() is doing.
I just want to know if there is a safer way to store data or a way so that the user can't manipulate the data before clicking the button.
Consider this function:
function setupPrivateData(element) {
var private = 1;
element.setPrivate = function ( d ) { private = d; }
element.getPrivate = function ( ) { return private; }
}
When called with some DOM element it will add two methods to it: .setPrivate(val) and .getPrivate().
These are the only methods that will allow you to access and modify that private variable associated with the element.
The user can always manipulate data. Nothing stops an advanced user to access object properties or call a jquery.data() on their own.
Something you could do in vanilla js would be:
var div = document.getElementById("test");
div.something = "hidden value";
div.addEventListener("click", function() {
alert(this.something);
});
<div id="test">click me</div>
The best way would to be a serverside verification if the sent data is valid or not.
Besides that, you could try to wrap your code in an anonymous function to deny the user access to the object:
(function() {
var data = {};
data.something = "test";
})()
But even that fails as soon as the user manipulates your files and adds for instance a debugger statement.
You can obfuscate your javascript but the only validation has to be done on your server. For example, I tried to get the weather from theweathernetwork. They have hidden their API call using multiple files and callbacks. In my opinion, it's just more challenging (funnier) if you want to reverse-engineer their site.
Javascript can't be secure. Never trust user input
If you are logging button clicks, the safest way to keep track is to save and validate on the server side.
For example, when you click a like button on Soundcloud, it makes an HTTP request to Soundcloud's server, records that you clicked the button, and marks it as a favorite. This way, if the same user clicks the button anytime in the future, it can check before incrementing the number of favorites.
The number displayed in the button is also pulled in from the database when the view is rendered.
This is a huge topic, and you have a lot to learn, far too much for a comment here. Anything "stored" in an attribute in the HTML source is absolutely not secure, it can be changed very very easily.
The most common way of dealing with this would be to use a cookie, but even with some effort these can be manipulated.
If security is important, find some way of identifying your users (possibly by IP, but even that isn't fool proof!) and keep the data on your server, linked to a user ID which can be retrieved after the button is clicked.

Some SiteCatalyst eVar values not passing in Custom Link

I'm facing a crazy matter with a SiteCatalyst Custom Link (internal) request.I'm firing an s.tl() through the code below:
var s_custom = s_gi("report-suite");
s_custom.linkTrackVars = "eVar76,events,list3";
s_custom.linkTrackEvents = "event87";
s_custom.events = "event87";
s_custom.eVar76 = "value";
s_custom.list3 = "option1,option2";
s_custom.tl(this, 'o', 'link name');
The issue concerns the eVar76, whose value is not included in the request, even if the "s_custom" TrackerObject contains it. In fact, if I inspect that object I find it.This strange seems to affect just "high" number eVars, like eVar76, 77, 80, 99 and so on, not lower ones.Replacing eVar76 with eVar55, 56 or 60, for ex, is resulting in a normale behaviour where values are normally included in requests.This is not depending on eVars existance, or activation, in the report suite and this is expected because no preliminar calls are made to Adobe server in order to check the set, or enabled, eVars in that report suite.This is a very silly behaviour forcing me to replace the desired eVar with another one.I just add that this Custom Link is prepared by a Page-load (DOM ready) rule in the Adobe DTM, but I suppose that no particular setting should be done in order to fix it.This is the first time that an SC variable is not included in request as expected.Thanks so much for supporting me.
The core Adobe Analytics library code builds the request string with a loop that looks for events/eVars up to the max available. Adobe Analytics only recently expanded events from 100 to 1000 and eVars from 75 to 100/250, so in order to accommodate this increase, an update to the core AppMeasurement library code was made.
Note: Although Adobe has been making updates to the Legacy H library alongside AppMeasurement, they did not update the Legacy H library to accommodate this increase. So, in order to track eVar76+ and event101+ within javascript as the variable (e.g. s.eVar76='foobar'), you must upgrade to the latest AppMeasurement library.
Alternatively, if you are using Legacy H.23+ library you can instead populate it as a contextData variable and then map it to the event/eVar/prop in a processing rule (e.g. s.contextData['eVar76']='foobar' and then in processing rule you'd have e.g. if [(contextdata) eVar76] [is set] then overwrite [eVar76] with [(contextdata) eVar76])
Reference: https://marketing.adobe.com/resources/help/en_US/sc/implement/evars_events.html

getComponent Code for openDocAsReadOnly

Is it possible to differentiate how documents open in a view on an XPage, depending on the status of a document using the getComponent("programmaticname").getValue() method?
If the status of the document is "Sent" then I want it to open in Edit mode. If the status of the document is "Reviewed" then I want it to open in Read Only mode.
I would like to compute the "openDocAsReadOnly" property in my view. Could someone show me what that code would look like?
This is a working example:
<xp:viewPanel
rows="30"
id="viewPanel1"
var="rowData">
<xp:this.facets>
<xp:pager
...>
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
viewName="yourView">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
id="viewColumn2"
displayAs="link"
columnName="Reviewer"
openDocAsReadonly="#{javascript:rowData.getColumnValue('Status') === 'Responded'}">
</xp:viewColumn>
It is important that
viewPanel has var="rowData" so openDocAsReadonly can reference to current row with rowData....
view column Status has not only "Status" as title but as Programmatic use name too
If all works fine then the URL of your Reviewer column should end with &action=openDocument if Status is "Responded" and &action=editDocument for all other cases.
Maybe the cause for you having trouble to get it to run is much easier: use for test "Responded", not "Reviewed". In your former question you told Status is called "Reviewed", so answers use this. But, your picture here shows "Responded".
Make sure you define a variable name in your viewPanel at All Properties >> data >> var (rowData is a frequently used variable name for that)
This variable holds an object of type NotesXspViewEntry, so it knows a method called .getColumnValue(colName:String), where colName is your Notes view column's programmatic name (I assume it's named "Status").
In consequence your openDocAsReadonly property could hold a code like this:
rowData.getColumnValue("Status")=="Responded"
EDIT:
sorry maybe made a mistake here; probably it doesn't work due to a wrong timing. Instead you could try to override the standard url link by defining it in the viewColumn's pageUrl property. A quick test revealed a code like this (I followed Knut Herrmann's observation):
var d = entry.getColumnValue("Status");
var a="editDocument";
if(d=="Responed") {
a="openDocument"
}
"/yourDocXpage.xsp?documentId=" + entry.getUniversalID() + "&action=" + a
Not really sure though whether this is the best of all solutions...

Trying to save open MS Access documents from JScript

I was hoping to save all open MS Access documents via a JScript run from the Windows Script Host.
So far I was able to obtain the MS Access object by calling:
var objAccess = GetObject('', "Access.Application");
But now I'm stumped. If it was MS Word, I'd enumerate all open documents in the .Documents property and call Documents.Item(n).SaveAs() method on each of them.
But how do you save-as all open documents in MS Access?
After you have your object variable set to an Access application instance with GetObject, use its Quit method with the acQuitSaveAll option (value = 1). Not sure about JScript; in VBScript, I can do it like this.
Dim objAccess
Set objAccess = GetObject(,"Access.Application")
WScript.Echo objAccess.CurrentDb.Name
objAccess.Quit(1) ' acQuitSaveAll
Set objAccess = Nothing
Note, when I used GetObject as in your example, objAccess was a new Access application instance rather than a reference to the instance which was running previously. So, with the GetObject line like this ...
Set objAccess = GetObject('', "Access.Application")
... the WScript.Echo line threw an error with CurrentDb.Name (because there was not a database open in that Access application instance.
This approach will save any changes to database objects (tables, forms, reports, etc.) which were in design mode but not saved. However if a user has any unsaved changes to data in a form, those changes will be discarded despite the acQuitSaveAll option. It seems that option only applies to objects, not data.
Edit: If that approach is not satisfactory, you can do something more sophisticated with VBA in your Access applications, as #Remou mentioned in his comment. An example is KickEmOff from Arvin Meyer. He also offers a sample database which demonstrates that code in action.
Edit2: Remou's comment got me thinking acQuitSaveNone (value = 2) should be safer than acQuitSaveAll ... the unsaved object changes would be discarded, but at least you would be less likely to save an object in a non-functional state.

Categories