It's all about the answers!

Ask a question

ARTIFACT_SAVED Event in DNG is going for endless loop for updating an attribute value in Doors Next Extension


Chandan M B (952561) | asked May 06, 8:20 a.m.

 Hello,


I am using an Event ARTIFACT_SAVED, where I am trying to update the attribute value of a requirement. Even though code works, it is calling infinite number of times and filling the values continuously for an attribute.
My code block looks like below

    var toSave = [];
        let attrResult = await services.getAttributes(selection);
        console.log(attrResult[0].values["XXX"]);

        await attrResult.forEach(item => {
            var current = item.values["XXX"];
            var newTextValues = constructFindings(current);
            if (newTextValues) {
                // Reuse the existing RM.ArtifactAttributes
                item.values['XXX'] = newTextValues;
                toSave.push(item);
            }
        });
       

        let operationResult = await services.setAttributes(toSave);
        for (p of operationResult) {
            if (p.code != "OK") {
                console.log(p.code + " Problem update artifact '" + p.message);
                return "ERROR";
            }
        }

One answer



permanent link
Ralph Schoon (60.5k33643) | answered May 06, 8:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I would consider this a "recursion" where a save is caught and an update (a save) is performed, which causes another trigger, which causes another update and so forth. This would be expected behavior, unless you build a mechanism that detects the update has been done and breaks the recursion.


Comments
Chandan M B commented May 06, 8:53 a.m.

Yes it is recursion But I am not understanding why the save event is calling more than once in Doors Next when we modify only one time. Event is captured recursively 


Ian Barnard commented May 10, 5:32 a.m.
JAZZ DEVELOPER

If you're saving a value to the attribute that's going to cause another Event ARTIFACT_SAVED. Have you tried changing your code so it doesn't save to the attribute  unless the value has changed from what it already is? And ensure that the new value isn't dependent on its previous value else you'll still get recursive changes.

Your answer


Register or to post your answer.