How to make all requirements start with the requirement ID (in brackets), in IBM Rational DOORS? - scripting

I have 3 attributes:
ID
Text
Is Requirement?
Here's an example of what I want:
Before:
ID Text Is Requirement?
AB45 3.1.2 Apples FALSE
AB46 All apples shall be red. TRUE
After:
ID Text Is Requirement?
AB45 3.1.2 Apples FALSE
AB46 [AB46] All apples shall be red. TRUE
Is there a programmatic way to add ID's to the front of the "Text", only if "Is Requirement?" is TRUE? If so, where exactly would the code go and how would you execute it? Would it be an additional DXL attribute?

Not directly. An attribute can either be calculated or manually filled, not both at the same time. Perhaps you might want to have two views, one "Edit view", one "Show Requirements View". In the latter, you will not show the main column (main column shows "Object Heading" and "Object Text"), but you will have a DXL Layout column with a code like this:
bool objIsReq = obj."Is Requirement?"
if (objIsReq) {
display "[" identifier(obj) "] " obj."Object Text" ""
} else {
if (!null obj."Object Heading""") then display number (obj) " - " obj."Object Heading"""
if (!null obj."Object Text""") then display obj."Object Text"""
}

Related

Google Docs API for creating invoice containing table of variable number of rows

I have a template file for my invoice with a table with sample row, but I want to add more rows dynamically based on a given array size, and write the cell values from the array...
Template's photo
I've been struggling for almost 3 days now.
Is there any easy way to accomplish that?
Here's the template file: Link to the Docs file(template)
And here's a few sample arrays of input data to be replaced in the Template file:
[
[
"Sample item 1s",
"Sample Quantity 1",
"Sample price 1",
"Sample total 1"
],
[
"Sample item 2",
"Sample Quantity 2",
"Sample price 2",
"Sample total 2"
],
[
"Sample item 3",
"Sample Quantity 3",
"Sample price 3",
"Sample total 3"
],
]
Now, the length of the parent array can vary depending on the number of items in the invoice, and that's the only problem that I'm struggling with.
And... Yeah, this is a duplicate question, I've found another question on the same topic, but looking at the answers and comments, everyone is commenting that they don't understand the question whereas it looks perfectly clear for me.
Google Docs Invoice template with dynamically items row from Google Sheets
I think the person who asked the question have already quit from it. :(
By the way I am using the API for PHP (Google API Client Library for PHP), and code for replacing dummy text a Google Docs Document by the actual data is given below:
public function replaceTexts(array $replacements, string $document_id) {
# code...
$req = new Docs\BatchUpdateDocumentRequest();
// var_dump($replacements);
// die();
foreach ($replacements as $replacement) {
$target = new Docs\SubstringMatchCriteria();
$target->text = "{{" . $replacement["targetText"] . "}}";
$target->setMatchCase(false);
$req->setRequests([
...$req->getRequests(),
new Docs\Request([
"replaceAllText" => [
"replaceText" => $replacement["newText"],
"containsText" => $target
]
]),
]);
}
return $this->docs_service->documents->batchUpdate(
$document_id,
$req
);
}
A possible solution would be the following
First prep the document by removing every row from the table apart from the title.
Get the full document tree from the Google Docs API.
This would be a simple call with the document id
$doc = $service->documents->get($documentId);
Traverse the document object returned to get to the table and then find the location of the right cell. This could be done by looping through the elements in the body object until one with the right table field is found. Note that this may not necessarily be the first one since in your template, the section with the {{CustomerName}} placeholder is also a table. So you may have to find a table that has the first cell with a text value of "Item".
Add a new row to the table. This is done by creating a request with the shape:
[
'insertTableRow' => [
'tableCellLocation' => [
'rowIndex' => 1,
'columnIndex' => 1,
'tableStartLocation' => [
'index' => 177
]
]
]
]
The tableStartLocation->index element is the paragraph index of the cell to be entered, i.e. body->content[i]->table->startIndex. Send the request.
Repeat steps 2 and 3 to get the updated $doc object, and then access the newly created cell i.e. body->content[i]->table->tableRows[j]->tableCells[k]->content->paragraph->elements[l]->startIndex.
Send a request to update the text content of the cell at the location of the startIndex from 5 above, i.e.
[
'insertText' => [
'location' => [
'index' => 206,
]
],
'text' => 'item_1'
]
]
Repeat step 5 but access the next cell. Note that after each update you need to fetch an updated version of the document object because the indexes change after inserts.
To be honest, this approach is pretty cumbersome, and it's probably more efficient to insert all the data into a spreadsheet and then embed the spreadsheet into your word document. Information on that can be found here How to insert an embedded sheet via Google Docs API?.
As a final note, I created a copy of your template and used the "Try this method" feature in the API documentation to validate my approach so some of the PHP syntax may be a bit off, but I hope you get the general idea.

Taskjuggler - Resource name in taskreport

Ho can I make the resource names appear in the task reports? There is a column 'resources' that I simply use as such:
taskreport overview "" {
scenarios plan
columns bsi { title 'WBS' },
name, start, end, resources, chart { width 1400 ${TaskTip} }
period 2021-07-30 +9m
}
However, this will put the resource ID and the name in it. E.g. if I have a resource like:
resource w1 "Worker One" {}
the column will contain "w1 (Worker One)".
But I just want the name.
You can add parameters to the resources column specification. This does the trick:
resources { listitem "<-query attribute='name'->" }

How to check if a key element exists and if present update it?

I am using mule community edition. So no Dataweave. I am consuming a rest service in my application. In the json response from this backend rest service. I need to check if a particular element exists inside muliple multiple elements of an array and wherever it exists I need to update its value.
E.g. (sample)
Input Request : [ { "id" : "1", "item" : "car", "make" : "Tonda" }, { "id" : "1", "item" : "car" } ]
using foreach to iterate array . Inside for each need to do something like below in expression component.
if( payload.make exists) { payload.make = "Tero"; }
But I do not know , how to check "if element exists"" condition. I tried below in expression component
if( payload.make != empty) { payload.make = "Tero"; }
But it did not work and gives error "Execution of the expression failed (org.mule.api.expression.ExpressionRuntimeException)"" for each array element wherever the particular key(make) is not present
inside foreach use the expression: #[payload.containsKey('make')] to check if the json key make exists or not. This will return true or false
Easy and simple!
Ref: https://forums.mulesoft.com/questions/71478/how-to-check-if-a-key-element-exists-and-if-presen.html?childToView=71502#answer-71502
Tested in a flow, if your payload is a single object and not a collection you can do MEL:
#[(payload.?make != empty) ? "EXISTS" : " OPS NO"]
Just change "EXISTS" with your true condition and "OPS NO" with the false one.
According to documentation: https://docs.mulesoft.com/mule-user-guide/v/3.7/mule-expression-language-reference
Null Safety
To access properties in a null safe manner, add the .? operator before one or more objects in a chain. In the following expression, if fieldA is null, the expression evaluates to null instead of a NullPointerException.

Cloudant Search field was indexed without position data; cannot run PhraseQuery

I have the following Cloudant search index
"indexes": {
"search-cloud": {
"analyzer": "standard",
"index": "function(doc) {
if (doc.name) {
index("keywords", doc.name);
index("name", doc.name, {
"store": true,
"index": false
});
}
if (doc.type === "file" && doc.keywords) {
index("keywords", doc.keywords);
}
}"
}
}
For some reason when I search for specific phrases, I get an error:
Search failed: field "keywords" was indexed without position data; cannot run PhraseQuery (term=FIRSTWORD)
So If I search for FIRSTWORD SECONDWORD, it looks like I am getting an error on the first word.
NOTE: This does not happen to every search phrase I do.
Does anyone know why this would be happening?
doc.name and doc.keywords are just string.
doc.name is usually something like "2004/04/14 John Doe 1234 Document Folder"
doc.keywords is usually something random like "testing this again"
And the reason why I am storing name and keywords under the keywords index is because I want anyone to be able to search keywords or name by just typing on string value. Let me know if this is not the best practice.
Likely the problem is that some of your documents contain a keywords field with string values, while other documents contain a keywords field with a different type, probably an array. I believe that this scenario would result in the error that you received. Can you double check that all of the values for your keywords fields are, in fact, strings?

Unable to select a value from a dropdown of windows form using AutoIt

Using the following code
ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "This is my default value (TEST) - First")
or
ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")
It selects the combo box, but it is not selecting the desired "this is my default value (TEST) - First" from the list. Basically, it is selecting any value that starts with t. For example, the first value is "TMP". So instead of exactly matching it is selecting any first character match. How do I force it to select the exact string from the list?
I also tried using the following code, but nothing seems to work.
WinWaitActive($title)
$Index = _GUICtrlComboBoxEx_FindStringExact($hcombo, $sText)
_GUICtrlComboBoxEx_SetCurSel($hcombo, $Index)
or following
WinWaitActive($title)
$Index = _GUICtrlComboBox_FindStringExact($hcombo, $sText)
_GUICtrlComboBox_SelectString($hcombo, $Index)
Right now you are using ControlSend with incorrect parameters. The following will send the string 'select', and the last parameter will be evaluated to 0.
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")
As it expects 1 or 0 as the last parameter). Needless to say it's not what you want.
You should be doing something like SelectString with ControlCommand. You shouldn't have to show the dropdown first:
ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "SelectString", "This is my default value (TEST) - First")
I haven't been able to test that, but as long as it's finding the window and the string is correct then it should be fine.