How to select DOORS attribute by reference attribute : DXL Script - attributes

I have database of doors requirements in a module.
There are 2 attribute for each requirement. When I select first attribute value as A, then second attribute value 1 should automatically get updated with that reference.
Similarly for B -> 2, C -> 3
Using a DXL script, how do I get this functionality?

You need to make attribute 2 a DXL attribute with the following code:
string attr1 = "NAME_OF_ATTRIBUTE_1"
string attr2 = "NAME_OF_ATTRIBUTE_2"
if(obj.attr1 "" == "A") {
obj.attr2 = 1
} else if(obj.attr1 "" == "B") {
obj.attr2 = 2
} else if(obj.attr1 "" == "C") {
obj.attr2 = 3
}
Good luck,
Steve

Related

Replace Values Conditionals

I want to replace values based on certain conditions. I can do this for the values in a specific column but I am not sure how to convert the code to have it work for all values in a range of columns.
This is my code currently:
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ColumnNames = Table.ColumnNames(Source),
Step1 = Table.ReplaceValue(Source,
each[L1_Grade],
else if Text.Contains([L1_Grade], "A") then "Upper"
else if Text.Contains([L1_Grade], "B") then "Middle"
else if Text.Contains([L1_Grade], "C") then "Lower"
else if Text.Contains([L1_Grade], "NaN") then ""
else if Value.Is(Value.FromText([L1_Grade]), type number) then "Num"
else [L1_Grade], Replacer.ReplaceText, ColumnNames)
in
Step1
How do I modify my code so it works for any of the columns specified using ColumnNames? I am not sure what to replace [L1_Grade] with.
Assuming, you have such table:
Then you may use following code:
let
Source = Excel.CurrentWorkbook(){[Name = "Data"]}[Content],
replace = Table.ReplaceValue(
Source,
0,
0,
(a, b, c) =>
let
f = (x) => Text.Contains(a, x),
y = try Number.From(a) otherwise a
in
if y is number and not Number.IsNaN(y) then
"Num"
else if f("A") then
"Upper"
else if f("B") then
"Middle"
else if f("C") then
"Lower"
else if f("NaN") then
""
else
a,
Table.ColumnNames(Source)
)
in
replace
Some comments:
Of course, you may use different list of columns in the last argument of the function.
The code may be simplified, if numbers are always as type text and/or may be only single version of "NaN".
If the replacement logic should be case-sensitive - adjust this line:
f = (x) => Text.Contains(a,x,Comparer.OrdinalIgnoreCase),
But since "NaN" contains "a" letter, some other code changes are required.

How to use match on String value with Scala?

I'm trying to iterate on a String value to change each occurence of it.
For example i want that "1" become "one", "2" become "two", etc.
I've done this :
override def toString = {
val mapXX = init.map(_.clone);
var returnVALUE = mapXX.map(_.mkString).mkString("\n")
for(c <- returnVALUE){
c match {
case 1 => "one";
case 2 => "two";
...
case _ => "";
}
}
returnVALUE
}
}
It didn't change anything of my list, i have the same display of my list. Nothing has changed.
Did someone knows how can we iterate on each character of a String value in order to replace each character by something else ?
Thanks
It's not completely clear what you're doing. Try
returnVALUE.map {
case '1' => "one"
case '2' => "two"
case '3' => "three"
// ...
case _ => " "
}.mkString
and this should be the last line of toString.
String#map accepts a function from Char to something (e.g. to String).
If returnVALUE is "1 2 3" then this produces "one two three".
When the last line is returnVALUE this means you return the original value of returnVALUE, not the modified value.
A for comprehension without the yield clause doesn't create any results. It can only be used for side effects, which good Scala programmers try to avoid.
Maybe something like this.
val numberNames = Map(0 -> "zero", 1 -> "one", 2 -> "two").withDefaultValue("too big")
val result = List(2,0,1,4).map(numberNames)
//result: List[String] = List(two, zero, one, too big)

I want to change let's say the values of [a b c d e] within a text which has repeated occurrences of these letters with values [f h d o t] all at once

I can easily replace each every letter by doing them one after another but when i use loop it won't.
a = strrep(a,'b','z');
a = strrep(a,'a','e');
a = strrep(a,'c','f');
but for i = 1:size(a,2)
a = strrep(a,'b','z');
a = strrep(a,'a','e');
a = strrep(a,'c','f');
end
only change 'b' and 'a' not all. so lets say if we str 'abcdabc' then replace one after another gives right answer but loop shows the result as 'ezedeze'. so please help with this.
Here are two approaches:
With changem (from the Mapping Toolbox):
str = 'basic example string';
old = 'abcde';
new = 'fhdot';
str = changem(str, new, old);
With ismember:
str = 'basic example string';
old = 'abcde';
new = 'fhdot';
[ind1, ind2] = ismember(str, old);
new = 'fhdot';
str(ind1) = new(ind2(ind1));

Jira Groovy Script Numeric Textbox value

I use Jira 4.0
Jira has a meaning on numeric textbox.
I'm checking in the Groovy Script this space and I assign a variable as below.
value = (String)WorkflowUtils.getFieldValueFromIssue(issue, WorkflowUtils.getFieldFromKey("customfield_10507")) ?: ""
If the value I assign to “value” variable, which is written on customField, is greater than 200 as shown above, it should execute.
Example:
if (value > 200)
{}
else if (value < 200)
{}
My issue is that it detects it as smaller than 200 if the first digit of the number is smaller than 2, such as:
value = 10 – 100 – 150 – 165 – 1000
For instance; When I type 45,30,50,89 it accepts it as greater than 200
You need to cast the value to Integer. Use toInteger() method on non-empty String object.
It should be something like:
def value = (String) WorkflowUtils.getFieldValueFromIssue(issue,WorkflowUtils.getFieldFromKey("customfield_10507"))
def valueNum = value?.isNumber() ? value.toInteger() : 0//You may change the default value
Solution:
value = '56.0'
value2 = value.replace(".0", "");
int convertedNumber = Integer.valueOf(value2).intValue()
if (convertNumber > 200)
{}
else if (convertNumber < 200)

Compare one string to all elements of an array

How do I get the result when '#' exist in the string will return 1 else 0. Now, I get the results of 0 0, although second string contain the character of '#'.
A = {'#'};
B = {'http://www.mathworks.com/help/matlab/ref/strcmpi.html',
'http://www.mathworks.com/help/matlab/ref/strcmpi#dfvfv.html'};
match = strcmpi(A,B)
Output:
match =
0
0
Desire Output
match =
0
1
Edit2:
why do i use the same concept as above but i get the wrong results? I want to check whether the file that store in 'data14' got 'javascript' & 'disableclick' at the same time. But the results return me all '1'.
for i = 1:4
A14 = {'javascript'};
B14 = {'disableclick'};
data14 = importdata(strcat('f14data/f14_data', int2str(i)));
feature14_data=any(cellfun(#(n) isempty(n), strfind(data14, A14{1}))) & any(cellfun(#(n) isempty(n), strfind(data14, B14{1})))
feature14(i)=feature14_data
end
This can be used to get desired output:
cellfun(#(n) ~isempty(n), strfind(B, A{1}))
You could use ismember iteratively:
cellfun(#(x)ismember('#',x), B)

Resources