Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Edit Item, Update Properties

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
835 Views, 8 Replies

Edit Item, Update Properties

I am trying to edit a item and set a new unit of measure and then UpdateAndCommitItem() to save changes.

 

Private Function editItem(ByVal SelectedItem)

        Dim items As Item() = ItemSvc.GetAllLatestItems()

        For Each item As Item In items
             Dim eitem As New ItemService.Item
             eitem = ItemSvc.EditItem(item.RevId)
eitem.Units = "FT"
Next Return True End Function

 I am getting error 1387 while doing eitem = ItemSvc.EditItem(item.RevId)

... but I assume if that would work I'd just do eitem.Units = "FT" followed by a UpdateAndCommitItem() and I am not sure on the parameters I'd have to input... just the properties I'm updating?

 

Thanks

 

8 REPLIES 8
Message 2 of 9
Redmond.D
in reply to: Anonymous

Correct, setting the Units property on the object and calling a Commit function is how you change the units.

 

I recommend calling UpdateAndCommitItems whenever possible.  It's much easier to work with than the function without the 's' at the end.

 

Anyway, your failure is at EditItem, so you need to find out what that error means.  When you get one of the RestrictionsOccurred errors, you need to find the real reason by digging into the XML data on the SoapException.  See the Restriction Codes page for more information on how to parse the XML.



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 3 of 9
Anonymous
in reply to: Anonymous

System.Web.Services.Protocols.SoapException was unhandled
  Actor="http://config-mgmt-srv/AutodeskDM/Services/ItemService.asmx"
  Lang=""
  Message="1387"
  Node="http://config-mgmt-srv/AutodeskDM/Services/ItemService.asmx"
  Role=""
  Source="System.Web.Services"
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at Vault.ItemService.ItemService.EditItem(Int64 itemRevisionId) in C:\Documents and Settings\mspears\My Documents\Visual Studio 2005\Projects\Vault\Vault\Web References\ItemService\Reference.vb:line 2331
       at Vault.Explorer1.editItem(Object SelectedItem) in C:\Documents and Settings\mspears\My Documents\Visual Studio 2005\Projects\Vault\Vault\Explorer1.vb:line 210
       at Vault.Explorer1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\mspears\My Documents\Visual Studio 2005\Projects\Vault\Vault\Explorer1.vb:line 199
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at Vault.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

 This is the only Stack Trace I get, and the only error code is 1387, I don't see a restriction code?

Message 4 of 9
Redmond.D
in reply to: Anonymous

The stack trace doen't have the restriction codes.  You need to cast the Exception to type System.Web.Services.Protocols.SoapException and look in the Detail property.



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 5 of 9
Anonymous
in reply to: Anonymous

Could you please show me how to do this?

 

Appreciate it!

Message 6 of 9
Redmond.D
in reply to: Anonymous

I don't have any code handy for getting at the restriction codes.  However I have an article that explains how to get the error code.  The code has an example of how to cast the Exception to a SoapException.  Once you have the SoapException object, copy the Detail value and post it so that I can take a look.



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 7 of 9
Anonymous
in reply to: Redmond.D

I figured out the restrictions, thank you for your help... I am having trouble using UpdateAndCommitItems(). I understand it takes the following properties to update and commit items:

<ns:UpdateAndCommitItems>
         <ns:itemRevisions>
            <ns:Item RevId="?" RevNum="?" LastModUserName="?" LastModUserId="?" LastModDate="?" MasterId="?" ItemNum="?" ItemTypId="?" Title="?" Detail="?" Id="?" VerNum="?" Comm="?" Units="?" LfCycStateId="?" UnitId="?" NumSchmId="?" CadBOMStructId="?" ControlledByChangeOrder="?" EffStart="?" EffEnd="?"/>
         </ns:itemRevisions>
      </ns:UpdateAndCommitItems>

 I am able to edit the item, but when I try to commit:

 

 Dim eitem As New ItemService.Item
                    eitem = ItemSvc.EditItem(item.RevId)
                    eitem.Units = "Liquid Ounce"

                    ItemSvc.UpdateAndCommitItems(eitem)

 Doesn't work, says it's a one-dimensional array, so I might have to combine a string with all those properties?

 

Thanks again,

Message 8 of 9
Anonymous
in reply to: Anonymous

Ok, got past that part with this code:

 Try
            Dim items As Item() = ItemSvc.GetAllLatestItems()

            For Each item As Item In items
                If item.ItemNum = SelectedItem Then
                    Dim eitem As New Vault.ItemService.Item
                    eitem = ItemSvc.EditItem(item.RevId)
                    eitem.Units = "Liquid Ounce"
                    eitem.UnitId = 16

                    ItemSvc.UpdateAndCommitItems(New Item() {eitem})
                    MsgBox("Updated")
                End If
            Next
            Return True
        Catch E As System.Web.Services.Protocols.SoapException
            MessageBox.Show(E.Detail("sl:sldetail").InnerText)
        End Try

 All seems to go good, but it doesn't actually update the item with the new unit of measure.

 

Any help is appreciated!

Message 9 of 9
Redmond.D
in reply to: Anonymous

That code looks correct to me.  Are you sure that UpdateAndCommitItems is actually being called?  Maybe the if statement is weeding out all the items.

 

Also, you don't need to update the Units property.  Updating UnitId should be sufficient.



Doug Redmond
Software Engineer
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report