You are viewing limited content. For full access, please sign in.

Question

Question

Invalid Request Error when calling Laserfiche via SDK - Moving Documents

SDK
asked on March 15, 2018

Getting an error when trying to move a document and assign metadata.  Below is the code I am using -- I receive an error 'Invalid Request' from the Laserfiche response.  

using (Session mySess = new Session())
                    {
                        RepositoryRegistrationCollection repoRegColl = myServ.GetRepositories();
                        RepositoryRegistration myRepoReg = repoRegColl[LFServerRepository];
                        if (myRepoReg == null)
                        {
                            myRepoReg = new RepositoryRegistration(LFServerName, LFServerRepository);
                        }
                        mySess.LogIn(user, pwd, myRepoReg);
                        FolderInfo folder = Folder.GetFolderInfo(destFolderId, mySess); //Folder 22201430 will not change
                        foreach (var externalDocumentId in externalDocumentIds)
                        {
                            //Get document info -- 21997011 = Current document m
                            DocumentInfo doc = Document.GetDocumentInfo(externalDocumentId, mySess); //Enter your document ID here
                            //Get folder info -- This will be static, you will ALWAYS move to this folder ID
                            //Initiate the move in Laserfiche -- Autorename the document if name already exists
                            doc.MoveTo(folder, doc.Name, EntryNameOption.AutoRename);
                            //Get existing field values so that we do not overwrite existing data
                            FieldValueCollection FVC = doc.GetFieldValues();
                            //Lock the document so no other users attempt to open the file
                            //doc.Lock(LockType.Exclusive);
                            //Add the field values, the first section is the field name, then the second is the value we're passing                            
                            if (parentDocumentId > 0 && parentDocumentId != externalDocumentId)
                            {
                                if (FVC.Any(c => c.Key == "Parent ID"))
                                    FVC["ParentID"] = parentDocumentId; //Parent Document Id  laserfiche will append this child document to parent
                                else
                                    FVC.Add("ParentID", parentDocumentId);
                            }
                            else
                                parentDocumentId = externalDocumentId;

                            FVC.Add("Username", userName); //STRING
                            FVC.Add("DateTime", DateTime.Now); //DATETIME FORMAT TIME USER CHECKED DOCUMENT IN                           

                            if (!string.IsNullOrEmpty(shipmentId))
                            {
                                FVC.Add("Document Type", "BOL Code"); //STRING
                                                                      //THIS MUST BE IN S####### FORMAT OR IT WILL FAIL
                                if (FVC.Any(c => c.Key == "Shipment ID"))
                                    FVC["Shipment ID"] = shipmentId;
                                else
                                    FVC.Add("Shipment ID", shipmentId);
                            }                           

                            doc.SetFieldValues(FVC);
                            //Save & Unlock document
                            doc.Save();
                            //doc.Unlock();
                        }

Please let me know where I am going wrong.  

Thanks,

Nate

0 0

Answer

SELECTED ANSWER
replied on March 15, 2018

Your code works for me (it moves the document, it fails later because I don't have fields with those names).  There might be more information in the event viewer on the LFS machine.  You might try testing with a simplified version, and adding functionality.  When it stops working, you'll know what caused it.

0 0

Replies

replied on March 15, 2018

Is it the move that's failing, or one of the other lines of code?

0 0
replied on March 15, 2018

Yes, it is the move that is failing.  

doc.MoveTo(folder, doc.Name, EntryNameOption.AutoRename);

Thanks,

Nate

0 0
SELECTED ANSWER
replied on March 15, 2018

Your code works for me (it moves the document, it fails later because I don't have fields with those names).  There might be more information in the event viewer on the LFS machine.  You might try testing with a simplified version, and adding functionality.  When it stops working, you'll know what caused it.

0 0
replied on March 16, 2018

Brian,

It worked when I changed the file name from 'BrownsvilleProTrans@protrans.com_20180314 (113)' TO - 'Brownsville BOL' and it worked successfully.  I did not test to see if it was a special character (@_()) or the length of the file name.  Either way, I have it working as expected.  

Thanks,

Nate

0 0
replied on March 16, 2018

It seems like it's the '.' character in the name.  Note that there are MoveTo() overloads that don't take a name parameter that don't seem to exhibit this problem.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.