Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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
}

0 votes



4 answers

Permanent link
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

1 vote

Comments

I can not write the whole text here, so I wrote it down as answer

Is this a once off or a regular thing? Your simplest approach in that case would be an Excel export, a macro, and a reimport of the new enum value.

I feel development of some sort of server or separate client to do just this thing would end up taking much longer than exporting a predefined View with the right filter and attributes and an import, even if this had to be done daily

1 vote


Permanent link
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);
   }
}


1 vote

Comments
The main problem here is that the RM Client API works through event listeners and they trigger through the UI, which will only let you select a maximum of 200 artefacts at a time.

How are you building your artifactList? Are you populating that some other way than via selection in the UI?

Dear Jean-Francois,


thank you so much for your hint. I tried it out in splitting the artifacts to be changed in arrays in batches and afterwards update only these batches one after the other. Now it looks find (I could update more than 10.000  items whithout getting an error).

Dear Davyd,

I build my list using the function  RM.Data.getContentsAttributes(moduleRef,[RM.Data.Attributes.ARTIFACT_TYPE, attributeToChange, RM.Data.Attributes.IDENTIFIER], (result)=>{

Best regards,

Antje

1 vote

In the UI, the limitation is indeed a maximum of 200 artifacts. To overcome this limit, one of the first operations performed by my widget was to generate a list of artifacts of a certain type (for example, all artifacts of type "Requirement"), the number of which, depending on the module, can be well over 200. To do this, I used the "RM.Data.getContentsStructure" function to retrieve all the artifacts from the module and generate the "artifactList".

I admit that I spent some time making the widget's interface more fluid and preventing it from freezing while "RM.Data.setAttributes" did its work. There's nothing more frustrating or unsettling for a user than not seeing the progress of the processing; therefore, batch processing seemed the most appropriate solution.

Next, I did not want to go beyond the limits of the application by launching updates, with "RM.Data.setAttributes", of several hundred artifacts.


Permanent link

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?

0 votes


Permanent link

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.

0 votes

Comments

Dear Ian, 


thank you for your answer.

I could solve it with Jean-Francois hint below.

Best regards,

Antje

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,085

Question asked: Mar 04, 7:38 a.m.

Question was seen: 157 times

Last updated: yesterday

Confirmation Cancel Confirm