最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Change Spotfire Document Properties value using javascript - Stack Overflow

matteradmin9PV0评论

I want to Change the value assigned to a Document Property in spot fire. Lets say i have created a new document property called "Test1" as a string and assign it a value "a". Is there are way to change this value using Javascript every time i load the spotfire dashboard ?

I want to Change the value assigned to a Document Property in spot fire. Lets say i have created a new document property called "Test1" as a string and assign it a value "a". Is there are way to change this value using Javascript every time i load the spotfire dashboard ?

Share Improve this question asked May 23, 2016 at 19:22 DrakeDrake 951 gold badge4 silver badges8 bronze badges 1
  • If the answer below worked for the question posted, please accept it or add any clarifying ments you need :) – S3S Commented Jun 6, 2016 at 21:18
Add a ment  | 

4 Answers 4

Reset to default 1

I'm unaware of a way to use JavaScript for this, but you can assign a string document property via custom expression (if it's a List Box) or run an IronPython script each time the value changes. So, you could set the expression to the current date, datetimenow() and then every time it's loaded the IronPython script would fire. However, I don't see why you'd need the property control for this.

I suppose it really depends on what you want the document property to be set to. Is it data from your tables? Output from plex code? These are all things to consider.

1) Create an input type property control using the Document Property you want to change.

2) Edit Html to assign parent element an id say "testInput". And add the script as shown below in the Edit HTML window.

<span id="testInput"><SpotfireControl id="7db34e6c423240f59fc99e6b80fa23ec" /></span>


<script>
$("#testInput input").val("after");
$("#testInput input").focus();
$("#testInput input").blur();
</script>

3) This script will change the document property value to "after" whenever you open a file.

As you ment seemed to suggest, something you can do is write this code in Python and attach the script to an action control, e.i. a Link or a Button. Something simple like: Document.Properties["Test1"] = newValue or even: Document.Properties[changingProperty] = newValue allowing the code to be more reusable.

Then you insert Javascript into the Text Area as well to the effect of: $("#VeryLongSpotfireControlID").click();

Which should simulate clicking on action control, which in turn triggers the Python script to update the value. Just be careful not to use this approach when it would result in reloading the text area HTML, as this will re-trigger the Javascript, thus creating an endless loop.

I believe I have found a possible solution/work-around for the issue, entirely based on pure JavaScript (since TIBCO removed jQuery starting from Spotfire X). The solution is to force a simulated Enter Keystroke while focusing the input box to trigger updating the Document Property. (No data function and R needed)

HTML (SpotfireControl Element is an single line input-box for a Doc. Prop.):

<div id="container"><SpotfireControl id="b8534f13dc62416db6d4eaab16030f5e" /></div>

JS (focus and blur might no longer be needed for this solution, but I'm still keeping them just in case):

const inputConfirmationEvent = new KeyboardEvent("keypress", {
    keyCode: 13,
    bubbles: true,
    cancelable: false
});

var elem = document.querySelector("#container input");
elem.value = "stringValue";
elem.blur();
elem.focus();

document.querySelector("#container input").dispatchEvent(inputConfirmationEvent);

Hope it helps someone.

Best, Aaron

Post a comment

comment list (0)

  1. No comments so far