Assigning a value to a "local" variable with M2Doc

59 Views Asked by At

I need to do the following, but I am struggling.

  1. I declare a variable to false
  2. I start a for loop that includes an if statement. If this statement is evaluated at true during one of the loops, I want to assign true to my variable.

I have tried to use a let construct, but 1. I am not sure this is the proper way to achieve what I want and 2. I am not sure about the syntax for changing the value of my variable.

{m:let test=false}
   {m:for x|...}
      {m:if aStatement=true}
         {m:test=true}    // this line does not work, the syntax is probably wrong
      {m:endif}
   {m:endfor}
{m:endlet}

Thank you very much for your help!

Given the anwers provided, I am putting my original code hereunder, with the original mistake of believing I could change the value of a variable, because I struggle understanding the instructions. Would you be able to indicate me whether 1. the let construct is the right thing to use and 2. what should be in me let statement?

{m:let test = false}

{m:for req | PIDSREQ.eAllContents()->filter(Requirements::Requirement)} 
   {m:for allocreq | req.eContents()->filter(CapellaRequirements::CapellaIncomingRelation)}
      {m:if allocreq.target=SF}
         {m:test = true}
      {m:endif} 
   {m:endfor}
{m:endfor}

{m:if test = false}
NO REQUIREMENTS
{m:endif}

{m:endlet}

Thank you

1

There are 1 best solutions below

7
Yvan Lussaud On

Variables are immutable in M2Doc, you need to use an AQL expression instead:

let test = aCollection->any(e | e.expression) <> null

The any() service returns the first element that matches the given expression. Then we test is such element is not null.