Start a new topic

/back:: vs Context:/back::

Hi,


Mainly /back:: and Context:/back:: have two differences, which are where the operation is performed and the returned set of items.

 

/back::

Returns a list of all items in the DB which include the current obj as the specified part.

The use of this axis is executed by the server, and is potentially expensive, especially if you run on a slave server.


Note: The use of /back:: is NOT recommended due to the potentially negative effect on performance for all system users.  


Example:

<Report>
  <ForEach select="IRSS">
    <ForEach select="/back::IRSS">
      <Text>#{Name}</Text>
    </ForEach>
  </ForEach>
</Report>

Result:

image



Context:/back::

If you must /back::, it is recommended to use it in a Context since it would not have an impact on system performance.

Returns a list of all items in the current context which include the current obj as the specified part.

The use of this axis is executed by the client, which result in faster performance.  


Example:

<Report>
  <Context name="document">
    <AddParts owner="main" sid="IRRS" part="documentSection" defobj="section"/>
    <AddParts owner="section" sid="ISSE" part="subSection" defobj="subSections"/>
  </Context>
  <ForEachInContext name="document" group="section">
    <ForEach select="Context:/back::documentSection">
      <Text>Item name: #{Name} Version:#{Version}</Text>
    </ForEach>
  </ForEachInContext>
</Report>
Result:

image

Best Regards,
Bashar





1 person has this question

How to move back in the Context definition? I need something like:

<AddParts owner="ProductFunc" sid="back::2IS370"  part="PFtoPost"  defobj="Post"/>

Hi Mikael,


To move back in a context you should do that in two steps


Step 1: You should define your context for example

  <Context name="context1">
    <AddParts owner="main" sid="ARSC" part="softwareComs" defobj="SoftwareComponent"/>
    <AddParts owner="SoftwareComponent" sid="ARPP" part="receiveSignals" defobj="Signal"/>
    <AddParts owner="SoftwareComponent" sid="ARRP" part="sendSignals" defobj="+Signal"/>
  </Context>


Step 2: when you iterate over the defined context, in the above step, you can choose to go forward or backward. To go backward you have two different alternatives which will give the same result, the first alternative is to use the tag <ContextGoBack part="">

For example

 <ForEachInContext name="context1" group="Signal">  
  <ContextGoBack part="sendSignals">
    <Text>- #{Name}</Text>
  </ContextGoBack>
  </ForEachInContext>


and the second alternative  is to use the Path language using Context:/back::

For example 

  <ForEachInContext name="context1" group="Signal">  
  <ForEach select="Context:/back::sendSignals">
    <Text>- #{Name}</Text>
  </ForEach>
  </ForEachInContext>


Here you can find a full example for how to define a context (Step 1) and then iterate over the defined context with going backward (Step 2)

<Report>
    <Context name="context1">
        <AddParts owner="main" sid="ARSC" part="softwareComs" defobj="SoftwareComponent"/>
        <AddParts owner="SoftwareComponent" sid="ARPP" part="receiveSignals" defobj="+Signal"/>
        <AddParts owner="SoftwareComponent" sid="ARRP" part="sendSignals" defobj="+Signal"/>
    </Context>


    <ForEachInContext name="context1" group="Signal"> 
        <!--Alternative 1--> 
        <ContextGoBack part="sendSignals">
            <Text>- #{Name}</Text>
        </ContextGoBack>
        <!--Alternative 2-->
        <!--
        <ForEach select="Context:/back::sendSignals">
            <Text>- #{Name}</Text>
        </ForEach>
        -->
    </ForEachInContext>
</Report>



For more information about how to use context please visit SystemWeaver Script Language - Introductory Training 


Thanks,

Bashar


Thanks Bashar


My problem with this context of mine is I need to define the context with two "heads". The Post is not subordinated to the main, As I try to illustrate in the attached picture I need to go from main down to a  Product Function item. From this I need to back up via a different part to the Post, and from there down into the PHAR analysis via a third part.

The trick to define an item to a context when this item is outside the main sub-structure I understand is to define it (the Post) as the value of a Parameter. In syntax this seams to work and I have followed several examples in the documentation and at the support.systemweaver.se (e.g. https://support.systemweaver.se/support/discussions/topics/31000002342?page=1), but this fails for me with the "Please select Parameter" error message in the generated document/report.





Hello again,


If I understood your use case correctly then using a context with parameter will solve your issue.  If you have the need to select a value that is on a higher level than your main item then you can use parameter, i.e., define a Parameter to select the Post value in you case. Here I am including an example for how to do that:


<Report>

    <Parameters>
        <Parameter caption="Analysis Area" name="p1" hintContextPath="I2AHA;DEIT"/>
        <ForEachPathReference path="I2AHA;DEIT">
            <AddParameterValue name="p1"/>            
        </ForEachPathReference>
    </Parameters>


    <Context name="HARAContext">
        <AddParts owner="p1" sid="I2AHA" part="AnalysisToHARA" defobj="HARA"/>
        <AddParts owner="HARA" sid="DEIT" part="AnalysisToItem" defobj="main"/>
        <AddParts owner="HARA" sid="DEHA" part="AnalysisToHazard" defobj="Haz"/>
        <AddParts owner="HARA" sid="DEHE" part="AnalysisToHazEv" defobj="HazEv"/>
        <AddParts owner="HARA" sid="DESG" part="AnalysisToSafetyGoal" defobj="SafetyGoal"/>
        <AddParts owner="main" sid="I2SID" part="ItemToDetail" defobj="Detail"/>
        <AddParts owner="main" sid="I2IRQ" part="ItemToDetail" defobj="+Detail"/>
        <AddParts owner="SafetyGoal" sid="SGDF" part="SafetyGoalToHazEv" defobj="+HazEv"/>
        <AddParts owner="HazEv" sid="HEH" part="HazEvToHaz" defobj="+Haz"/>
        <AddParts owner="Haz" sid="I2HO" part="HazToDetail" defobj="Detail"/>
        <AddParts owner="Haz" sid="I2HARQ" part="HazToDetail" defobj="Detail"/>
    </Context>

  
    <ForEachInContext name="HARAContext" group="main">
        <ForEach select="Context:/back::AnalysisToItem/AnalysisToSafetyGoal">
        <Text>#{Name}</Text>
    </ForEach> 
    </ForEachInContext>
</Report>


 



Thanks,

Bashar

Login to post a comment