It's all about the answers!

Ask a question

RTC Scripting - Use an XML file as data source


Gilles Trautmann (2134) | asked Nov 21 '12, 7:03 a.m.
edited Apr 08 '13, 12:48 p.m. by Ralph Schoon (56.5k23642)
Hi,

I have been developing some scripts to customize my work items for a few days/weeks now and thanks to this forum I have learnt a lot :)

However I am facing an issue to which I cannot find an answer.

I have several custom attributes which are linked and I would like to auto-update some of them according to another one.

To be more specific :
- I have a list of requestors (about 300 people)
- Each requestor is bound to a location and a cross asset
- I would like to set up automatically the location and the cross asset as soon as a requestor is selected. (The best would be to be able to select several requestors. So far I have a multi-select list in my editor but it is not very user-friendly to have 300 items in it so I am open to any suggestion and I will probably create a new post for that too.)

At first the requestor list contained only 50 people so I wrote 2 "calculated value" scripts in which I mapped each user to either its location or its cross asset and I updated the value this way.

Now that the list has expanded a lot, I think the best way would be to have an xml file in which would have the following structure :

<xml>               
    <node>               
        <id>1</id>   
        <name>Requestor 1</name>
        <crossAsset>Cross asset 1</crossAsset>
        <location>Loc1</location>
    </node>       
....
</xml>


Is there a way to "call"/load this xml file and manipulate it using dom in a script ?

Thank you

Gilles

3 answers



permanent link
Ralph Schoon (56.5k23642) | answered Nov 21 '12, 7:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You could try to use the HTTP filtered value provider if the XML is published on a HTTP server. I know you can't use it to just read the file. You could store the data you need for post-processing in this attribute. If you use this, you would probably have to create some script that, based on the data in the field calculates values for the other attributes. I have seen limitations on list type attribute values with scripts, so I can't tell if it would work for you.

The Scripts can access XML data in the process configuration. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_Example . I am no sure there is a way to access XML files from java script. I would be interested to know, if one has built a working solution..


Comments
Vladimir Amelin commented Nov 21 '12, 7:51 a.m. | edited Nov 21 '12, 7:52 a.m.

We developed pre-condition for RTC 2.0. which reads its configuration from process template source xml. So it's realizable using Java SDK for sure.


permanent link
Gilles Trautmann (2134) | answered Nov 21 '12, 9:38 a.m.
Hi Ralph,

Thank you for your quick answer.

I tried to use the HTTP filter value provider but I was not able to publish the XML on a HTTP server.

I finally managed to do something else :

- I created a "Value Sets" script called "ValueSetProvider". This script returns a multidimensional array in which all the info are available
var users = [   ["Name1", "Location1", "CrossAsset1"], 
                ["Name2", "Location2", "CrossAsset3"],
                ..... ]; 

- I created another "Value Sets" script called "ValueSetFiltering" which includes the "ValueSetProvider" script defined earlier, I am them able to define a new object which type is ValueSetProvider. In this "ValueSetFiltering" script I take advantage of the "Filtered" property and I am then able to filter the names just as I wanted to do. Besides I can always use the  ValueSetProvider object in other scripts in order to validate/invalidate some info.

Comments
Ralph Schoon commented Nov 21 '12, 9:56 a.m. | edited Nov 21 '12, 9:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

From a lab that is going to be published with the Process Enactment Workshop soon:

  • You can publish your own data easily using Apache. Install Apache as described in this article and place an XML document into the folder <Apchae-Install_Dir>/htdocs. You can also provide a different folder as described in the article mentioned above.



Gilles Trautmann commented Nov 21 '12, 9:59 a.m.

Unfortunatley I cannot install anything on my machine. My work environment is very restricted :(


permanent link
Gilles Trautmann (2134) | answered Nov 21 '12, 9:54 a.m.
edited Nov 21 '12, 10:22 a.m.
Ok well, apparently that works in the Eclipse Client but not on the web client (neither on IE nor on FF).
Since I added the Value Sets scripts, I always receive an error message when creating a workitem>

Picture is attached below



The strange thing is that the error occurs on a Validator script which used to work perfectly. Code is given below :

dojo.provide("SED.Validator.Location");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity=com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;
dojo.declare("SED.Validator.Location", null, {
validate: function(attribute, workItem, configuration) {
                        var nbAvailableLocations = 8;
			var value = workItem.getValue(attribute);
			var values = value.split(",");
			if (value.indexOf("l6") != -1)  // i.e. "All" is selected
			{
				if (values.length > 1){
					return new Status(Severity["ERROR"], "If \"All\" is ticked, other values should not be selected")
				}
				return Status.OK_STATUS;
			}
			else if (values.length == nbAvailableLocations) {
				return new Status(Severity["ERROR"], "Select \"All\" instead of ticking all other values")
			}
			return Status.OK_STATUS;
        }
    });
})();


Is there a problem with Value Sets scripts ? (I am working on RTC 3.0.1.1 and as I have tested that on IE 7 and Firefox 16.0.2)

EDIT : Actually all my previous scripts do not work anymore and I get a similar error message as soon as a script is triggered


Comments
Ralph Schoon commented Nov 21 '12, 10:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I have never seen an error like that  - ever - when running a script customization.

I assume scripting is on. Try to delete the attachment from the projects process attachments (LinksTab and right lover editor in Eclipse Project Area Editor) and try to reload it.

Otherwise, are you using process sharing and have uploaded it in the shared project?

There are also many fixes that went into scripting when going to 4.x. 


Gilles Trautmann commented Nov 21 '12, 10:24 a.m. | edited Nov 21 '12, 11:01 a.m.

Yes I already tried to delete and reload attachments but I still get the same errors.

I am not using process sharing ("Do not share this project area's process" ticked in Overview tab => Process Sharing in Eclipse)


Ralph Schoon commented Nov 21 '12, 11:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

If you manage the project area in the web UI and look for Process Sharing and that shares the process from another project area you are using this feature. I have heard about some at least in 4.x with customizing the process in certain situations. However,it is just a shot into the blue.

Your answer


Register or to post your answer.