Open form from library 1, change, submit to library 2, delete from library 1 - InfoPath Dev
in

InfoPath Dev

Open form from library 1, change, submit to library 2, delete from library 1

Last post 01-02-2009 05:41 AM by Shiva. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-2009 07:10 AM

    Open form from library 1, change, submit to library 2, delete from library 1

    The form I'm working with is a timesheet. The employee submits it to a "supervisor" library. The supervisor will open the form, digitally sign it, then submit it to a "payroll" library. At this point I need the copy in the supervisor library to be deleted. The problem I have is it returns "Access is denied". I think the problem is the form has not completely closed by the time the delete is called and it thinks the file is still in use. I know the code works because if I tell it to delete a file I'm not currently in it works fine. It will even fail if I change "DELETE" to "GET". I have checked the path that is being passed and I have checked permissions. Maybe someone can tell me where I've gone wrong. What's really strange is if I skip the submit and go straight to the delete it works fine! I'm using 2003. Here's the functions I have:

    private sub DeleteXmlDoc(strUrl)
        ' Create the XMLHTTP object
        dim objXmlHttp
        set objXmlHttp = CreateObject("MSXML2.XMLHTTP.5.0")
    
        ' ######## THIS IS WHERE IT FAILS #########
        objXmlHttp.Open "DELETE", strUrl, false
        objXmlHttp.send
    
        set objXmlHttp = nothing
    end sub
    
    private function SubmitXmlDoc(strUrl)
        dim fFileExists
        fFileExists = false
    
        dim blnSubmitSuccess
        blnSubmitSuccess = false
    
        ' Create an XMLHTTP object to transport the file.
        dim objXmlHttp
        set objXmlHttp = CreateObject("MSXML2.XMLHTTP.5.0")
    
        ' Attempt to open to the form location to check if a form with the same name already exists
        objXmlHttp.Open "GET", strUrl, false
        objXmlHttp.Send
        
        ' Status 200 or 201 = file exists
        ' This should never happen because the file name is time stamped to be unique
        if objXmlHttp.status = 200 or objXmlHttp.status = 201 then
            fFileExists = true
            XDocument.UI.Alert("Submit failed. The file already exists.")
        end if
     
        ' If no form at the same URL has been found, proceed to submit.
        if objXmlHttp.Status = 404 or not fFileExists then
            'Submit the form to the form library. 
            objXmlHttp.Open "PUT", strUrl, false
            objXmlHttp.Send XDocument.DOM.xml
      
            ' Status codes of 200 or 201 indicate that the form
            ' has been submitted successfully.
            if objXmlHttp.Status = 200 or objXmlHttp.Status = 201 then
                blnSubmitSuccess = true
            end if
        end if
    
        set objXmlHttp = nothing
    
        SubmitXmlDoc = blnSubmitSuccess
    end function
    
    private sub CTRL445_5_OnClick(eventObj)
        dim strUrl
        strUrl = "http://mysharepointsite/formlibrary/formname.xml"
    
        ' Try the submit
        if submitxmldoc(strUrl) then
            dim curDocUrl
            curDocUrl = XDocument.URI
     
            ' Close the file
            XDocument.View.Window.Close(true)
      
            ' Delete the old file
            DeleteXmlDoc(curDocUrl)
        end if
    end sub
    
  • 01-01-2009 09:22 PM In reply to

    Re: Open form from library 1, change, submit to library 2, delete from library 1

    Hi,

    Once replace the code line where you are getting error with the following.

    objXmlHttp.open("DELETE", strurl, False, UserName, PWD)

    Swathip
    www.ggktech.com
  • 01-02-2009 03:40 AM In reply to

    Re: Open form from library 1, change, submit to library 2, delete from library 1

    It still fails. I don't understand why when I comment out the "if submitxmldoc(strUrl) then" and "end if" that it deletes the file without a problem. Its seems as if the msxml2 is failing when I use it twice in succession. The submit and delete functions work fine independently, but when run together it gives me the access denied error. Do I have to clear out the msxml2 object some how before using it again?

  • 01-02-2009 05:41 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Open form from library 1, change, submit to library 2, delete from library 1

    Hello,

    After closing the form you are trying to delete the old file. Can you change close the form code after deleting the old file then it will work.

    Whenever you are trying to in one function create and another function try to delete it won't accept right. If you want to do this operation one after another, you have to use msxml2 object for both operation. It will give error If you try to create another object without closing the existing connection.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.