Modify "notes" in all workspace

Hello,

I want to update "notes" in all workspace with a project name change. There are about 500 plus workspace, in all workspace I have a note with title which has project name and table name.

So..trying to check if there is any shortcut to change the notes with new project name. Please advise.
Example: From Project name XYZ to ABC.

Thanks !!
Rajesh

Hi Rajesh,
I suppose that "Project Name XYZ" is just plain text in notes. So there is not any centralized place where you can rename it. if you use Stamp object for display Project name and other information, you can rename it in each stamp for all.
In your case it will be solution write simple script to rename. Bellow is fragment of code which should help you

function main(){
  var i;                                                       
  //Go throught all notes in model
  for(i=0;i<Model.Notes.Count;i++){
      var Note = Model.Notes.GetObject(i);
      //Filter out appropriate note
      if (Note.Text.search("Project Name XYZ")!=-1)        
      {
         //Here should be placed code for replaced text in Note
         Log.Information(Note.Text);
      }
  }
}

I hope it will help you

Hi Daril,

Yes its a plain text in notes. I am using below mention "Note" object to display project name and table names.

image

Do I still need to use the script mentioned by you ? Also, I am wondering whether I need to run this script in TDM, please advise.

Regards,
Rajesh

ok... I tried running the script shared by you in TDM scripting window by replacing the notes with new project name. However, getting runtime error message.

First time I am using this scripting window and I'm very sure I'm missing something, could you please email me directly so that I can share the error message ?

Regards,
Rajesh

Hi Rajesh,
scripting windows is easiest way how to run simple script. So I think it is suitable for this case.
The work with scripting window is easy, maybe you didn't select your model for scripting. Above of script editor is part where are all opened models. In the left part are all available, and you can move to the right part model (or more) which will be accessible in scripting window. BY default is the model accessible via variable "Model", but you can change it by inplace editor (select expression and press F2).

Inplace Editor

Output are typically to Message explorer, but there are more ways.

Another way to access model form scripting window is global object Application (See class CSApplication in Reference Guide). It has list of all opened models. So code below print names of opened models.

function main(){
  var i;                                                         
  for(i=0;i<Application.Models.Count;i++){
      var Mod = Application.Models.GetObject(i);
      Log.Information(Mod.Name);
  }
}

BTW: You can find property ActiveModel of Application, but when you are in scripting window, there is no active model. This property is possible to use in macros or other, but not in scripting window.

Daril

Hello Daril,

Here is my actual scope - Currently in all the workspace we have a note as below, and I need to replace eCash to Vergent.

Tried with the script below by selecting the required model, if you look at the script, currently I mentioned only the old name eCash, wondering where I should mention the new name Vergent in the script.

function main(){
var i;
//Go throught all notes in model
for(i=0;i<Model.Notes.Count;i++){
var Note = Model.Notes.GetObject(i);
//Filter out appropriate note
if (Note.Text.search("eCash")!=-1)
{
//Here should be placed code for replaced text in Note
Log.Information(Note.Text);
}
}
}

Successfully script has been executed, but I believe I need to mention the new name somewhere in the script, may be at the end where it says "Here should be placed code for replaced text in Note". Please let me know if I am missing something.

Thanks !!
Rajesh

Hi Rajesh,
you are right for your particular case you need code like this

function main(){
  var i;
  //Go throught all notes in model
  for(i=0;i<Model.Notes.Count;i++){
    var Note = Model.Notes.GetObject(i);
    //Filter out appropriate note
    if (Note.Text.search("Display notes:")!=-1)
    { 
      var str = Note.Text;
      str = str.replace("Display notes:","Vergent")
      //Here should be placed code for replaced text in Note      
      Note.Text = str;                                   
      Log.Information("New: "+Note.Text);     
    }
  }
}

You can see more about method replace

Daril

1 Like

Thanks for the additional information Daril. I have correct script now, ran the script and I could see the new note with correct project name.

After running the script, when I checked the workspace, it still has the old note. Is there any additional step to apply the changes in all workspace ?

Thanks !!
Rajesh

I explored “Script Explorer” by searching with some keyword in help topics.

Looks like I need to save the script in any of the folder in “Script Explorer” and commit the changes. If my understanding is correct, I would like to know how to use "Commit" in the script to apply the changes. I have not used script explorer/scripting window earlier. Please advise.

Thanks in advance.

Regards,
Rajesh

Use command

}
  } 
  Model.RefreshAllWorkspaces();
}

at the end of script above or reopen workspaces.
If you need it you can use Model.RefreshModel().

Btw: It is already changed, but workspace window has not been informed about it.

Daril

1 Like

Ah that's cool... By closing and reopening the data model I could see the changes. Thank you so much for all your support :slight_smile:

I will make a note of that final script to refresh all workspaces.

Regards,
Rajesh

Hello Daril,

Follow up clarification - By using the script, I changed the title in "note" few days back for all workspace.

However, I just noticed that if I double click the note, the top portion under "Name" has not changed. Please check the below screen snap, shown in Red.

If I generate an HTML report, for sure it will not show the old name eCash in the workspace. Still trying to check if there is an option or any other script to rename eCash to Vergent in the "Name" section. Please advise.

Thanks in advance.
Regards,
Rajesh

Hi Rajesh,
you have changed property "Text" of Note. If you would like name, than you will change property "Name".

...
Note.Text = str; //Current code in your script
Note.Name = newName; //variable new name has to has new valid name
...

Daril

Hi Daril,

I made the changes in the script, it worked !!

Thank you :slight_smile:

Regards,
Rajesh