Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi @all,
now it comes (again) to light that i'm not a programmer or coder...
I want to fill a relationship-field with some entries via setRelationShipFieldValue. I have some issue-id's as a comma-seperated list (stringlist). What i've tried is to write a trigger-script like this:
var delta = bsf.lookupBean("imIssueDeltaBean");
[...]
var arr = new Array();
arr = stringlist.split(",");
delta.setRelationshipFieldValue(TargetField, arr);
What i get is this:
JavaScript Error: The choice of Java method mks.ci.server.engine.LocalTriggerManager$ScriptIssueDeltaBean.setRelationshipFieldValue matching JavaScript argument types (java.lang.String,object) is ambiguous; candidate methods are: void setRelationshipFieldValue(java.lang.String,int[]), void setRelationshipFieldValue(java.lang.String,java.lang.Object[])
How can i avoid this errormessage or how can i choose the right java-method from inside the triggerscript?
Thanks for any hint...
cheers, Jens
Solved! Go to Solution.
OK, "setRelationshipFieldValue" seems to be more finicky then usual and the doc isn't much help. It does sound like the first method you tried (pass the whole string) should work but maybe they want it formatted with the flags too.
So here's my new plan:
var arr = new Array();
arr = stringlist.split(",");
var setRels = new java.util.ArrayList();
for ( i = 0; i < arr.length; i ++ )
{
setRels.add( parseInt( arr[ i ] ) );
}
delta.setRelationshipFieldValue( TargetField , setRels );
I hope it works.
First, you don't need to use java objects for that, you can do it all with JavaScript objects.
Second, what is "stringlist"? It's hard to tell where the problem comes from with so little context.
The split functions are different between JavaScript and java and use different arguments, java expects a regular expression.
I think you should use: var arr = new Array();
Hi Laurent, thanks for your answer. I actually did use arr = new Array(), it is already corrected in the first post. stringlist is a string like this:
"264739,488754,552893,45635434,445678"
It consists of Issue-ID's and commas, thats all. First i tried to put this list directly into the relationship-field, but i got the error message, that relationship-fields cannot use such strings.
OK, "setRelationshipFieldValue" seems to be more finicky then usual and the doc isn't much help. It does sound like the first method you tried (pass the whole string) should work but maybe they want it formatted with the flags too.
So here's my new plan:
var arr = new Array();
arr = stringlist.split(",");
var setRels = new java.util.ArrayList();
for ( i = 0; i < arr.length; i ++ )
{
setRels.add( parseInt( arr[ i ] ) );
}
delta.setRelationshipFieldValue( TargetField , setRels );
I hope it works.
Hi Laurent,
it works, you saved my day Thanks!
Cheers, Jens