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
Alle Svar (6)
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
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
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);
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.