Пакетное создание тегов в архитектуре предприятия с помощью JavaScript - PullRequest
0 голосов
/ 11 октября 2019

Я создал проект EA с кучей требований, которые необходимо импортировать в Redmine. Вместо того, чтобы делать это вручную, мы хотим использовать инструмент. Этот инструмент должен использовать определенный тег для синхронизации данных, поэтому мне нужно создать пять тегов для каждого требования, и я просто не могу сделать это для каждого требования, так как у меня сотнииз них.

Я начал проверять сценарии javascript, и я заметил функцию, подобную этой, в одном примере:

/**
 * Sets the specified TaggedValue on the provided element. If the provided element does not already
 * contain a TaggedValue with the specified name, a new TaggedValue is created with the requested
 * name and value. If a TaggedValue already exists with the specified name then action to take is
 * determined by the replaceExisting variable. If replaceExisting is set to true, the existing value
 * is replaced with the specified value, if not, a new TaggedValue is created with the new value.
 *
 * @param[in] theElement (EA.Element) The element to set the TaggedValue value on
 * @param[in] taggedValueName (String) The name of the TaggedValue to set
 * @param[in] taggedValueValue (variant) The value of the TaggedValue to set
 * @param[in] replaceExisting (boolean) If a TaggedValue of the same name already exists, specifies 
 * whether to replace it, or create a new TaggedValue.
 */
function TVSetElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */, taggedValueValue /* : variant */, replaceExisting /* : boolean */ ) /* : void */
{
    if ( theElement != null && taggedValueName.length > 0 )
    {
        var taggedValue as EA.TaggedValue;
        taggedValue = null;

        // If replace existing was specified then attempt to get a tagged value from the element
        // with the provided name
        if ( replaceExisting )
            taggedValue = theElement.TaggedValues.GetByName( taggedValueName );

        if ( taggedValue == null )
        {
            taggedValue = theElement.TaggedValues.AddNew( taggedValueName, taggedValueValue );
        }
        else
        {
            taggedValue.Value = taggedValueValue;
        }

        taggedValue.Update();
    }
}

Что мне нужно сделать, это какполучить список требований, которые хранятся в определенном пакете, и способы их циклического выполнения для применения этой функции.

Любая помощь будет принята с благодарностью.

1 Ответ

1 голос
/ 11 октября 2019

В основном:

for e in myPackage.elements:
    if e.type == 9: #code for Requirement
        print(e.name)
        for t in e.taggedValues:
            print(t.name, t.value, t.notes)

перечислит элемент пакета и все их теговые значения.

Это Python, но его нетрудно перевести на любой другой язык.

...