Rename a document in sharepoint to a custom name

lock
push_pin
done
Besvart
6

Hello everyone,

if this is the wrong forum for my question, take my apologies and please guide me to the correct forum...

I do want to rename a file (saved to sharepoint) based to the header name with CRMscript. But at least for our tenant, this does not work.

The script basically does this:

    String myNewHeader = myWantedHeader + docheader;
    String myDocumentName = myWantedHeader + docheader + ".docx";

    thing.SetHeader(myNewHeader);
    thing.SetName(agent.RenameDocument(myDocID, myDocumentName));
    agent.SaveDocumentEntity(thing);

The Header is set right, but the document does not seem to be renamed in sharepoint.

Also i do not get any error message - it just does not work.

Am i doing something wrong here?

Thanks and kind regards

Joerg Hermanns

 

10. jul. 2024 | 07:38 p.m.

Alle Svar (6)

Anybody ... ?

Am i the only one having this problem ??

6. aug. 2024 | 11:51 a.m.

Hello Jörg, 

I'm a little unsure about your code-snippet. Specifically this line:
```
  thing.SetName(agent.RenameDocument(myDocID, myDocumentName));
```
Is there a reason why you use the RenameDocument on the Agent in this way?

May I suggest you just set the name directly instead?
```
#setLanguageLevel 4;
NSDocumentAgent dAgent;
NSDocumentEntity dEntity = dAgent.GetDocumentEntity(59);
dEntity.SetName("NewName.docx");
dAgent.SaveDocumentEntity(dEntity);
```

That being said I can reproduce the issue with renaming documents when you use sharepoint. I'm looking into it and will get back to you in this thread when i have more information, hopefully the first part of next week. 

Have a SUPER day!

//Eivind

9. aug. 2024 | 11:47 a.m.

Hello Jörg, 

After digging into this there seems to be an issue with renaming files that are stored in sharepoint. 
We have created a bugreport on it, hopefully it will get fixed in the future..

Sorry!

//Eivind

13. aug. 2024 | 11:16 a.m.
Hello Eivind,
is there any news on this one?
I really need that document renaming badly ... some of our workflows depend on this currently.

Kind regards
Joerg
1. feb. 2025 | 01:17 p.m.
More than a year later .... is there ANY possibility to cleanly rename documents ... ? We want to have the document number and some more text in the filename when it is created in sharepoint. this really gets messy when that is not possible
Any hints on how to achive this?
We do create a Document Name in Superoffice like "Rechnung XXXXX - Beschreibung" and need the filename in the sharepoint library to be the same. As we do get the document number "XXXXX" only AFTER creating the document we need to rename the document.
Or am i missing something here ?
11 t, 37 m siden | 09:49 a.m.

Hi Jörg,

This was fixed in November last year. It seems that this thread was not updated back then. You are able to rename the document in SharePoint like this now:

#setLanguageLevel 4;

NSDocumentAgent dAgent;
NSDocumentEntity dEntity = dAgent.GetDocumentEntity(73);
dEntity.SetName("NewName.docx");
dEntity = dAgent.SaveDocumentEntity(dEntity);

 

10 t, 39 m siden | 10:47 a.m.
Hi Matthijs,
thanks for the information - then i will give it a try again.
Do you happen to know if there is an easy way to check, if the NEW name does collide with an existing document?
We need to make sure that i do not accidentally overwrite a different file with my new name.
So something like "if dEntity.FileExists() then ... // Rename with different name" ... ?

Thanks in advance
Joerg
10 t, 30 m siden | 10:56 a.m.

Hi,

It will never be overwritten, the API checks if the file already exists, and if it does, it will add a suffix to the filename. If we were to create a duplicate of the file with id 73, and rename it to NewName.docx, then the document name will become NewName (1).docx, because the original file already exists in the specific SharePoint folder.

9 t, 57 m siden | 11:30 a.m.

Legg til svar