4

We are migrating from Tridion 2009 to 2011 and I have a few problems with our custom popups for multivalued fields in Tridion.

In Tridion 2009 we could add an array as the returnvalue of the window (window.returnValue = new Array[]) and Tridion added the values into the component. This doesn't work anymore in Tridion 2011. It however does work for a single value --> window.returnValue = "New Value"

Can anyone help me with this? What should I change for the return value that it will work as it does in Tridion 2009?

2009 solution

var array = new Array();
var popupWindow = window.open("URL","","height=600, width=1000, scrollbars=yes, top=100, left=200, edge=Raised, center=Yes, help=No, resizable=No, status=No;");

//LOGIC HERE

array[0] = "Value 1";
array[1] = "Value 2";

window.returnValue = array;
window.close();

Tridion 2011

have no clue how to change this

3

In 2011 the window.returnValue is no longer used, so as you have already noticed you have to migrate your Custom URL scripts also.

It all starts with adding the PopupInit.js script to your Custom URL, which will register your Custom URL page allowing the script in there to make changes to the Component fields.

Then for the rest you have to work with window.dialogArguments and you will be able to access the current field from there. See below for a simple example of how to set the first two values of a multi value text field:

<html>
<head>
  <title>Custom Url example</title>
  <script type="text/javascript" language="javascript" src="/WebUI/Core/Controls/Popup/PopupInit.js"></script>
  <script type="text/javascript" language="javascript">
    function setValues(value1, value2) {
      var fields = window.dialogArguments.getFields();
      if (fields && fields.length > 0) {
        fields[0].setValues([value1]);
        fields[1].setValues([value2]);
      }
      window.close();
    }
  </script>
</head>
<body>
  <h1>Set values</h1>
  <ul>
    <li><a href="javascript:setValues('test 01', 'test 02')">Set values</a></li>
  </ul>
</body>
</html>

Now please note, this only works correctly if the multiple values are already available, if I'm not mistaking there still isn't a way to add a new (empty) field from a Custom URL directly (you can do that using the UI extension API).

| improve this answer | |
2

First, I'd try to make sure you are using the latest version of Tridion 2011 (there was a service pack and 2 hotfix rollups issued for this version).

According to this page in the documentation (login required) you can use a method called "setValues" to set the value(s) of Tridion fields:

<!-- Set the (first) value of the field. This assumes a field of type String -->
<script type="text/javascript">
  var fields = window.dialogArguments.getFields();
  if (fields && fields.length > 0) {
    fields[0].setValues(["Tridion"]);
  }
</script>

There isn't a specific example on that page that returns multiple values, but there are a few examples of manipulating multi-value fields. You can probably work it out from there?

| improve this answer | |
2

I'm pretty confident you can return an array and this will populate the multi-value fields, like this:

var values = new Array();
var fields = window.dialogArguments.getFields();

for (var i=0; i<fields.length; i++)
{
    values.push("adding value to field pos: " + i);
}
window.returnValue = values;
| improve this answer | |

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.