Skip to main content

Hello,

as suggested by Stephen Grant this is a new general topic, cause the prehistory / Idea may be closed. (which can be found here: Adding Task-Tickets to existing Linked Event Groupings via ETM | IFS Community )

Thanks to your Guidance, i was able to retrieve the nested linkedEventGroup id and linkReasonId for an event with the ETM Fields Parameter:

http://<server>:<port>/assystREST/v2/events/30003?fields=elinkedEventGroupsrid,linkReasonId]]

Now we aim to find a linkedEventGroup.id for a specified linkReasonId - with value 37 (as example).Thefore my next target is to filter this result.

https://wiki.axiossystems.com/assyst11-6Wiki/index.php/Category:assystREST#Field_Expansion_and_Filtering

The Wiki gives examples for filtering directly on a ressource, but i was unable to adapt these examples to filter on nested objects also.

Or is there a better way to solve this request with coding inside ETM?

A helpful hint would be appreciated :-)

 

Kind Regards

Christian

‘Filtering’ refers to the the fields that are returned, not to the values within those fields. You are alrteady using filtering in your Parent_Event ‘Fields’ definition where you are indicating that you only want the linked event data returned, and not all of the other fields for the event.

To find the specific bit of data (in a one:,many relationship) that yiu are interested in you’ll need to search through the results with JavaScript:

variable.Parent_Eventa0].linkedEventGroups
.filter(function(group){return group.linkReasonId==37})
.map(function(group){return group.remarks})
k0]

Should give you the remarks for the the group with link reason id 37.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter & https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map but note that the version of JavaScript used in ETM doesn’t support Arrow Functions  so we need to use the more verbose ‘function’ syntax (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)


Hello Paul,

thanks for the Javascript-Code. I adapted your solution for the Id instead of remarks. Therefore it can be used in a variable for the Record for Update. I also enclose it into “try-catch” to avoid undefined errors.

try {
variables.Parent_Eventv0].linkedEventGroups.filter(function(group){return group.linkReasonId==39}).map(function(group){return group.id})i0];
}
catch (ECMAException){ // Abfangen wenn noch keine Eventgruppe existiert

}

i also have a separate variable for the following 2 Mappers for the Linking for usage in “No value When...”

try {
if (typeof variables.LinkedEventGroupID !== 'undefined' && variables.LinkedEventGroupID.length > 0) {
// the array is defined and has at least one element
true;
}
else
true;
}
catch (ECMAException){ // Abfangen wenn noch keine Eventgruppe existiert
false;
}

As it is obvious i am no Java Professional. I believe there is definitely a smarter solution - but this one works for me at the moment. 😉

 

Kind Regards

Christian


Postscript:

the way above had the issue, that only the first set of Events would be linked, even when there are multiple Events.

Therefore i check for both EventMappers if the Event is included in the linkedEventGroup

 

var result = null;
if (variables.Parent_Eventt0].linkedEventGroups.filter(function(group){return group.linkReasonId==39}).map(function(group){return group.id}))0]) {
result = true;
}
result;

Kind Regards

Christian


Reply