Check Part or Product was selected - vbscript

I have a assembly like:
RootProduct:
SubProduct with Parts
Part 1
Part N
I'm writing code that check what type of item user selected and add new Part with my own parameters to the selected Product.
And I have a problem with checking what user selected.
If use code below:
InputType(0) = "Product"
Set ItemSelection = ActDoc.Selection
ItemSelection.Clear
SelStatus = ItemSelection.SelectElement2(InputType, "Choose Product", True)
If SelStatus = "Cancel" Then
Exit Sub
End If
If ItemSelection.Item(1).Type = "Product" Then
' add new Part
ElseIf ItemSelection.Item(1).Type = "Part" Then
MsgBox "It's Part. Script closed."
Exit Sub
End If
But problem is that in CATIA tree "Part" and "Product" have same type - Product.
Like this
May be exist another method how to check what type of data user selected?
Thank you.

Dim bIsProd as Boolean
Dim oSelectedProd as Product
Set oSelectedProd = ItemSelection.Item(1).Value
bIsProd = typename(oSelectedProd.ReferenceProduct.Parent) = "ProductDocument"
It is slightly more complicated if you are using "Visualization Mode" for your assembly In that case the property ReferenceProduct will fail. However, If your assembly is freshly opened and in "Visualization Mode" you may assume any ReferenceProduct properties that fail are Parts. Products will work.
It also may not work (I can't remember) if your documents are not saved yet.

Related

Outlook Macro's: Get user initials

I am working on a very, very simple project which sets a followup Flag on a selected message when running a macro.
I have created this so far which works very nicely, but I want to improve it by replacing the manual input of "YA" initials and put the default profile user initials as the initials.
I have found the contactitem object, but I have no idea how to get the initials out of it to put it as a .FlagRequest
Any idea's about this?
This is currently my code: (the GetCurrentItem just returns the selected email)
Public Sub SetCustomFlagNormal()
Dim objMsg As Object
Set objMsg = GetCurrentItem()
With objMsg
.MarkAsTask olMarkThisWeek
.TaskDueDate = Now
.FlagRequest = "YA"
.ReminderSet = True
.ReminderTime = Now + 2
.Save
End With
Set objMsg = Nothing
End Sub
The Outlook object model provides the CurrentUser property for the Namespace and Account classes. The property of the Namespace class returns the display name of the currently logged-on user as a Recipient object.
Sub DisplayCurrentUser()
Dim myNamespace As Outlook.NameSpace
Set myNameSpace = Application.GetNameSpace("MAPI")
MsgBox myNameSpace.CurrentUser
End Sub
The property of the Account class returns a Recipient object that represents the current user identity for the account. See the Name property of the Recipient class.
I have finally found a way.
After getting to multiple website, I was able to determine that Outlook doesn't offer a way to get the user initials and that Word has to be called upon to get the initials
As office uses the same initials throughout all office applications.
I got my response on this website.
http://blogs.technet.com/b/heyscriptingguy/archive/2008/03/18/how-can-i-retrieve-the-user-name-and-user-initials-from-microsoft-powerpoint.aspx
Hope it helps

CRM 2013 Dynamic OptionSet issue

I am using CRM 2013 On premise, and in it there is an attribute which has an option set (not global) having text and value as "Dummy Entry" "0". Default Value is unassigned.
My code is to add options in this option set with some business logic. So I can add new options in it via Javascript.
When I am adding Options in it via Javascript, it is not allowing me to change the value lets say
Option1 val1
Option2 val1 is added then it wont allow me to select these values and every-time selecting them will revert to default entry "--" and nothing will change.
But lets say I add
"Option1" "0"
"Option2" "0"
as text and values, they are shown finely and selecting any of them changes the text to "Dummy Entry".
Basically somehow if the value exists in the list of Options (which are static and not added via JS), it is accepting and selecting it and showing text from it.
If the value is not found in the static option list, it doesnt select anything and show default "--"
I hope I am clear, please let me know in case of any confusion. The following snippet is working in CRM 2011 while not working in CRM 2013.
// testing function
populateBundleLists: function () {
var bundleListControl = Xrm.Page.getControl("XXX_bundlelist");
var bundleOptions = bundleListControl.getAttribute().getOptions();
var bundleOption = bundleOptions[0];
bundleListControl.clearOptions();
// add some arbitrary values to control
for (var i = 1; i <= 7; i++) {
bundleOption.value = i;
bundleOption.text = 'Dummy bundle ' + i.toString();
bundleListControl.addOption(bundleOption, i - 1);
}
},
CRM stores OptionSets in the entity configuration and will need to know about all of the possible values. You cannot add new options using JS b/c the system will not be able to resolve your new value when someone queries using a different mechanism (Fetch XML, Advanced Find, filtered view, etc).

"Query is not understandable" - Full text searching where field types have changed

A client have a long lived IBM Notes application where someone along the line changed the type of a field from number to text.
So, now when we're trying to do an FT search like: [myField] = "1234" receive the error message: "Query is not understandable".
If I do: [myField] = 1234 it works but won't return any hits. Even though there's a document where myField = "1234".
The field is of type text in the design.
I've created a new view for testing, only allowing documents from one form.
Deleted the full text index (even on the file system)
updall -X
Fixup -r
Created full text index
In my test view I've got one column that shows if the field content being searched is of type text #IsText(myField) and all rows shows: 1 (so it's field content must be text)
None of the above worked so I created a new database copy locally.
Same problem.
Created an entirely new database (for testing only), form, view and full text index and that works.
Feels like the existing database design somewhere stores the old field type...
Any ideas appreciated.
Thanks!
/J
Datatypes and field names are stored in the UNK table. There is just one entry per field name, so it's critical not to use the same field name more than once in an application with different datatypes.
You need to rebuild the UNK table, as I blogged here http://www.intec.co.uk/full-text-search-musings/
Note, it must be an offline compact, as Duffbert says here http://www.duffbert.com/duffbert/blog.nsf/d6plinks/TDUF-5SMHV4. If anyone is in the database when you do the compact, it will fail and the UNK table will not be rebuilt.
Links are useful, but if you don't want to remove data from documents - for me such steps worked (and there was no need in removing fields from forms in designer):
Run from designer with manager access with such code inside
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim i As Integer
Dim nc As NotesNoteCollection
Dim noteid As String
Dim nextnoteid As string
Dim itemArr As Variant
Dim NeedSave As Boolean
Const ITEM_NAME = "itemName1|itemName2"
itemArr = Split( ITEM_NAME, "|" )
'погромист-кун не должен забывать про наличие итемов в формах...
Set db = s.Currentdatabase
Set nc = db.CreateNoteCollection(False)
nc.SelectForms = true
Call nc.BuildCollection
noteid = nc.Getfirstnoteid()
For i = 1 To nc.Count
Set doc = db.Getdocumentbyid( noteid )
noteid = nc.Getnextnoteid( noteid )
NeedSave = false
ForAll IA In itemArr
If doc.Hasitem( IA ) Then
Call doc.Removeitem( IA )
NeedSave = true
End If
End ForAll
If NeedSave Then
Call doc.Save( True, False )
End If
Print CStr( i ) & "\" & CStr( nc.Count )
Next
End Sub
Remove database index
Run from administrator command lo compact database.nsf -c , like mentioned in links above
Create index

How to add parameters to test cases in Test Plan using VBScript?

I got a piece of code in vbscript to add parameter to a test case
but it throws following error
Entity with Key '5' does not exist in table 'TEST'
VBSCRIPT:
Dim supportParamTest
Set supportParamTest = TDConnection.TestFactory.Item(5)
Set testParamsFactory = supportParamTest.TestParameterFactory
Set parameter = testParamsFactory.AddItem(Null)
parameter.Name = "name"
parameter.Description = "desc"
parameter.Post
Can anyone help me out?
You specifically asked for the TestFactory managed item whose id is '5' (line 2 of your code). The error tells you that there is no such entity with this id.
Did you mean to get item 5? If yes, are you connected to the right project?
You can check the entity IDs using the Admin feature that lets you run SQL directly against the HPQC project database. Do a SELECT * FROM TEST and see whether there is a row whose id is 5.

How to make a ComboBox column with two data sources (for DataGridView)

The data sources have the same structure, but different data. One would be used for rows that are saved (view mode), and the other one would be for rows that are being added or edited (edit/new rows). How can that be acomplished?
I have a standard foreign key column that references a standard lookup table which has an ID, Name and Active (bit). The combo box column uses that lookup table to show the list, but only active items. Let's say a lookup item is used and later deactivated (Active = 0). The combo box column now shows errors because the ID is not found in the list. Does anyone have any ideas how to solve it?
Not sure if you're still looking but I've just come across the same problem. Here's how I addressed it, hope it is of use to you.
Define a function which returns a DataGridViewComboCell with the appropriate datasource set (collection objects defined elsewhere, note that I'm using EntitySpaces in this example to populate the DataSource):
Private Function GetStockComboDataSource(ByVal type As eStockComboType) As DataGridViewComboBoxCell
Try
Dim cell As New DataGridViewComboBoxCell
Select Case type
Case eStockComboType.StockIn
cell.DataSource = Me.StockInCol.Query.LoadDataTable
cell.DisplayMember = "FullName"
cell.ValueMember = JCStockInMetadata.ColumnNames.StockItemID
Case eStockComboType.StockItem
cell.DataSource = StockItemCol.Query.LoadDataTable
cell.ValueMember = JCStockItemMetadata.ColumnNames.StockItemID
cell.DisplayMember = "FullName"
End Select
Return cell
End Function
Now when it comes to setting the combo DataSource (I use the RowEnter event here for example):
Private Sub dgvStock_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvStock.RowEnter
Try
If IsNumeric(Me.dgvStock.Rows(e.RowIndex).Cells("ID").Value) Then
Dim intValue As Integer = Convert.ToInt32(Me.dgvStock.Rows(e.RowIndex).Cells("Stock Item").Value)
Me.dgvStock.Rows(e.RowIndex).Cells("Stock Item") = GetStockComboDataSource(eStockComboType.StockItem)
Me.dgvStock.Rows(e.RowIndex).Cells("Stock Item").Value = intValue
Else
Me.dgvStock.Rows(e.RowIndex).Cells("Stock Item") = GetStockComboDataSource(eStockComboType.StockIn)
End If
Catch ex As Exception
JCExceptionLogger.LogException(ex)
End Try
End Sub
Here I switch the combo DataSource depending on whether the ID column is numeric but you can implement whatever business logic you require. Note that I save the value of the cell before setting the combo (intValue). This appears to be necessary otherwise the combo will display as blank.

Resources