Profile picture for user sumeet_satwani

Hi All,

I am struggling with a report in which I need to delete models from a group. I have developed a code its its giving me errors, error lines are marked in bold in the below code. Can someone please review the code and suggest me the correctives

var g_nLoc = 1033;

var g_oOutfile = Context.createOutputObject();

function main(){

 

  var oCurrentDatabase=ArisData.getActiveDatabase();

  var arrSelectedGroups = ArisData.getSelectedGroups();

  var arrSelectedmodels= ArisData.getSelectedModels();

 

 

  g_nLoc = Context.getSelectedLanguage();

  g_oOutfile.Init(g_nLoc);

 

   for( i = 0; i <=(arrSelectedmodels.length() - 1); i++){

  var modelGroup=arrSelectedmodels[i].Group();


   modelGroup.Delete(arrSelectedmodels[i]);

}

g_oOutfile.WriteReport(Context.getSelectedPath(), Context.getSelectedFile());

}

main();

 

by Freddy Barkhuizen
Posted on Fri, 07/08/2016 - 10:44

Hi Sumeet,

arrSelectedmodels.length() should be arrSelectedmodels.length

Also, when deleting objects in an array, delete from the back of the array.

Change your code as follows:

 for(i=arrSelectedmodels.length-1; i>=0; i--){

    var modelGroup=arrSelectedmodels[i].Group();

    modelGroup.Delete(arrSelectedmodels[i]);

 }

Regards,

Freddy

0
by Sumeet Satwani Author
Posted on Mon, 07/11/2016 - 05:52

Hi Freeddy,

I tried your code but its not going into this FOR loop .

When I decoded it, found the value of arrSelectedmodels.length-1 variable is =0 thats why its not entering into the loop.

But on the folder on which I am executing this script is having models into it..

Kindly please suggest what to do.

Thanks  :)

Sumeet

 

0
by Sumeet Satwani Author
Posted on Mon, 07/11/2016 - 07:09

Hi Freddy,

Just to add further Above code run  fine if executed on  Model(s) but I want  to execute it on a Group so that all the contained models are deleted.

How can we modify the above code according to my requirement.

Kindly suggest.

 

Thanks :)

Sumeet

 

 

0
by Sumeet Satwani Author
Posted on Mon, 07/11/2016 - 09:09

Hi Freddy,

I have created the Script and its working as per the expectation , Below is the code for it.

var g_nLoc = 1033;

var g_oOutfile = null;

function main(){

 

  var oCurrentDatabase=ArisData.getActiveDatabase();

  var arrSelectedGroups = ArisData.getSelectedGroups();

  var arrSelectedmodels= ArisData.getSelectedModels();

  var Ogroups =new Array();

  var OModels =new Array();

  var oCurrentModel =new Array();

 

  var oTargetGroup=oCurrentDatabase.Group(["Maersk Drilling - Maersk FPSOs","W. To be Deleted Models"],g_nLoc);

    var deletedModels=oTargetGroup.ModelList(true);

   var x=deletedModels.length;

  g_oOutfile = Context.createOutputObject(Context.getSelectedFormat(), Context.getSelectedFile());

 

  g_nLoc = Context.getSelectedLanguage();

  g_oOutfile.Init(g_nLoc);

  g_oOutfile.OutputLn(x+"' Models Deleted  '"+"'", "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, 0);

 

   for(i=deletedModels.length-1; i>=0; i--){

     var modelGroup=deletedModels[i].Group();

      g_oOutfile.OutputLn(deletedModels[i].Name(g_nLoc), "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, 0);

     modelGroup.Delete(deletedModels[i]);

  }

 

g_oOutfile.WriteReport(Context.getSelectedPath(), Context.getSelectedFile());

}

main();

 

Thanks for your Help :)

Sumeet

0

Featured achievement

Question Solver
Share your expertise and have your answer accepted as best reply.
Recent Unlocks
  • CR
  • BH
  • Profile picture for user Ivan.Ivanov.softwareag.com
  • Profile picture for user mscheid
  • MS
  • PacMan

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock