RM.Data.setAttributes
I can update with following code RM-artifacts, if there are less than 1000 artifacts. How can I get this work if there are more artifacts to be changed? Can I trigger a task tracker?
if (!filledItemList.includes(selectNewEnumText)){
filledItemList.push(selectNewEnumText)
//Reset the attribute value to the new list
attributeValues[attributeToChange]=filledItemList;
let singlePromise = new Promise((resolve)=>{
//update the artifact with adding the new enum-value
RM.Data.setAttributes(artifactAttributes, function(resultSetAttribute){
let resolveObject = {
result: resultSetAttribute.code,
artRef: item.values[RM.Data.Attributes.IDENTIFIER]
}
resolve (resolveObject)
})
})
promiseList.push (singlePromise)
}
Promise.all(promiseList).then((results)=>{
// some result-handling
}
5 answers
The DNG RM Client API is for working inside the UI directly and so cannot be used for mass updates, as this would cause performance issues.
You would need to develop something using the OSLC API, or a server side extension, but for this sort of work you could even use the built in Edit Attributes with a saved View. Create a View that selects all the artefacts you want to change, save it, and then use the menu beside it to bulk edit the attribute and set the enum value.
By creating a View the edit will be pushed to the server as a job that runs in the background, so you can update thousands of records at once
Comments
1 vote
I fully agree with the recommendation against using the RM API for bulk updates; however, in some cases, this type of update can be useful.
I encountered this bulk update (several hundred artifacts) and the resulting performance issues. To work around this, I adopted a batch update approach.
The example below illustrates this workaround.
The constant "MAX_ARTIFACT_UPDATE" defines the batch size, and "RM.Data.setAttributes" is called recursively until all batches are processed. A graphical indicator illustrates the update progress, and I must say, it works very well.
function set_Attributes (artifactList, updateIndex) {
const MAX_ARTIFACT_UPDATE = 20;
let myArtifactUpdList = [...artifactList];
let myArtifactUpdListCopy;
let myUpdIndex = (updateIndex === undefined ? 0 : updateIndex);
// ---- Disable buttons
gui_mgtButtonDrop (GUI_ITEM_UPDATE_BTN_ROOT, ACTION_ACTIVE_OFF);
// ---- Start batch update
if (myArtifactUpdList.length > myUpdIndex) {
mgt_Console(set_Attributes.name + ' : update block size (' + MAX_ARTIFACT_UPDATE + ') at index = ' + myUpdIndex, CONSOLE_INFO);
myArtifactUpdListCopy = myArtifactUpdList.slice(myUpdIndex, myUpdIndex + MAX_ARTIFACT_UPDATE);
myUpdIndex += MAX_ARTIFACT_UPDATE;
RM.Data.setAttributes (myArtifactUpdListCopy, function (result) { // ---- Call RM API to update attributes
$("#" + GUI_ITEM_NBARTANALYSE).text(g_LogReport.nbScannedArtifacts);
// ---- Set update status for each modified artifact
result.data.forEach (function (myArtifact) {
if (myArtifact.code === RM.OperationResult.OPERATION_OK) {
g_LogReport.nbUpdatedArtifacts++;
$("#" + GUI_ITEM_NBARTMODIFIED).text(g_LogReport.nbUpdatedArtifacts);
}
});
// ---- Manage batch update action and status
if (result.code === RM.OperationResult.OPERATION_OK) { // ---- All artifacts in batch are correctly saved
mgt_Console (set_Attributes.name + " : Successful update for block at index " + myUpdIndex, CONSOLE_INFO);
// ---- Compute the next block with a direct recursive call
set_Attributes (artifactList, myUpdIndex);
} else { // ---- Not all artifacts are correctly saved
mgt_Console (set_Attributes.name + " : Failed update for block at index " + myUpdIndex, CONSOLE_ERROR);
gui_MgtProgressIndicator (GUI_ITEM_UPDATE_ROOT, IS_ERROR);
$("#" + GUI_ITEM_MSGERROR).text("Failed to set attribute values !");
}
});
} else { // ---- End of batch update
mgt_Console(set_Attributes.name + ' : batch update is finished !', CONSOLE_INFO);
gui_MgtProgressIndicator (GUI_ITEM_UPDATE_ROOT, IS_SUCCESS);
// ---- Enable buttons
gui_mgtButtonDrop (GUI_ITEM_UPDATE_BTN_ROOT, ACTION_ACTIVE_ON);
}
}
Comments
1 vote
Thank you for your answer.
I can not use the bulk edit of the view, because I have to set different enums for the artifacts. As I know I can set with the bulk edit only the same enums for every artifact in the view.
I have to add - based on a already set enum - a new enum to the artifacts. E.g. if artifacts include the enum "abc" the enum "xyz" has to be added - all other enums, which are located in the artifact already should be unchanged.
I have not found an OSLC API to change artifacts in this way. Please can you give me a hint to do that?
The OSLC API will certainly do what you want but not in bulk - you'll have to GET each resource make the changes and PUT to update it.
You can maybe use OSLC Query to find all the artifacts you want to change, but you'll still have to GET then PUT to update them.
However as Davyd says it may be easier to export/import a spreadsheet.
I'm facing a similar limitation with bulk updates in RM. Curious if anyone has tried batching requests or integrating with a task tracker to overcome the 1000 artifact limit? Also, check out this tool for related automation solutions.