Create items with UDPs via API

Create items with UDPs via API

Jens.Bruhn
Enthusiast Enthusiast
1,560 Views
2 Replies
Message 1 of 3

Create items with UDPs via API

Jens.Bruhn
Enthusiast
Enthusiast

Hello,

I have some problems to fill item UDPs automatically.
My program imports items to VaultProf 2017 from a csv-file with individual number, title and title2 (UDP).
The import works fine, the items are generated but filling the UDP 'title2' fails.
( I tried the code from this post: https://forums.autodesk.com/t5/vault-customization/2015-r2-updateitemproperties/td-p/5461108 )


Here is my code snippet:

 

 

// Create Item
Item item = itemSvc.AddItemRevision(catID);
item.ItemNum = myItemNumberString;
item.Title = lineOfCsv[1].ToString();
itemService.UpdateAndCommitItems(new Item[] { item });
// Update UDP -> numberPropDefinition is the id of UDP 'title2' from PropertyService itemService.UpdateItemProperties( new long[] { item.RevId }, new PropInstParamArray[] { new PropInstParamArray() { Items=new PropInstParam[] { new PropInstParam() { PropDefId=numberPropDefinition.Id, Val=lineOfCsv[2].ToString() } } } } );

 


The result:
The items are generated with correct Number, Title and Category (first program part)
But after the second program part the item has lost his category and the UDP title2 isn't filled out !??

Any ideas?


Best regards,


Jens

0 Likes
Accepted solutions (1)
1,561 Views
2 Replies
Replies (2)
Message 2 of 3

sajith_subramanian
Autodesk Support
Autodesk Support
Accepted solution

Hi Jens,

 

The UpdateItemProperties API returns an array of items.  Can you try calling the UpdateAndCommitItems API on that.

So your code would be something like below:

 

// Create Item
Item item = itemSvc.AddItemRevision(catID);
item.ItemNum = myItemNumberString;
item.Title = lineOfCsv[1].ToString();
itemService.UpdateAndCommitItems(new Item[] { item });

// Update UDP -> numberPropDefinition is the id of UDP 'title2' from PropertyService


Item[] updated_items = 

itemService.UpdateItemProperties(
  new long[] { item.RevId },
  new PropInstParamArray[] {
    new PropInstParamArray() {
      Items=new PropInstParam[] {
        new PropInstParam() { PropDefId=numberPropDefinition.Id, Val=lineOfCsv[2].ToString() }
      }
    }
  }
);

connection.WebServiceManager.ItemService.UpdateAndCommitItems( updated_items);

 

 

Let me know if this helps.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 3 of 3

Jens.Bruhn
Enthusiast
Enthusiast

Hi Sajith,

 

so it works fine!

Thanx a lot for your help,

 

Jens

 

0 Likes