PDM API Using Historyafter & Historybefore in Searchtoken

Hi, everybody
I could not run the searchtoken Historyafter&Historybefore method in the code I shared.
“Date_Before & Date_After” type is “05.07.2021 00:00:00”

EdmLib.IEdmSearch6 search = (EdmLib.IEdmSearch6)vault.CreateUtility(EdmLib.EdmUtility.EdmUtil_Search);
search.SetToken(EdmLib.EdmSearchToken.Edmstok_HistoryAfter, Date_After.Value); 
search.SetToken(EdmLib.EdmSearchToken.Edmstok_HistoryBefore, Date_Before.Value); 
search.SetToken(EdmLib.EdmSearchToken.Edmstok_FindItems, true);
search.SetToken(EdmLib.EdmSearchToken.Edmstok_FindFiles, true);
search.SetToken(EdmLib.EdmSearchToken.Edmstok_AllVersions, false);

1 Like

I’m having the same issue you are having. I have sent an email to API support. I will let you know here about any updates.

I think there might be an issue with the VT_Date marshalling from .NET to COM.

@artem or @BigCrazyAl : Any thoughts?

1 Like

I believe you need to convert the DateTime to OLE date time: DateTime.ToOADate Method (System) | Microsoft Docs

I do not have PDM installed at the moment - cannot confirm if that works

1 Like

hi, @artem. i try that method. but it doesnt run.

DateTime sonrasiTarih = Date_Sonrasi.Value; //Date_Sonrasi -> datetimepicker
DateTime oncesiTarih = Date_Oncesi.Value;//Date_Sonrasi -> datetimepicker
double sonrasi_tarihi = sonrasiTarih.ToOADate();
double oncesi_tarihi = oncesiTarih.ToOADate();

search.SetToken(EdmLib.EdmSearchToken.Edmstok_HistoryAfter, sonrasi_tarihi); 
search.SetToken(EdmLib.EdmSearchToken.Edmstok_HistoryBefore, oncesi_tarihi);

@AmenJlili I’m able to get search results in the API, however they don’t really make sense so I went into the actual PDM tool and started messing with the History tab and the built in tools for the date before/after. I cannot for the life of me get anything that makes sense. I choose “Stored After Jul 5, 2021” and the entire list is legacy files that haven’t been touched since 2008 - 2011.
image

Unless I’m misunderstanding how the search is supposed to work, this appears broken.

Edit: I’ll leave the above, however I discovered that you have to search for ‘*’ in the “Text to find in history” or else it won’t work.

Edit2: The wildcard ‘*’ doesn’t seem to work for me when I set the

search.SetToken(EdmSearchToken.Edmstok_HistoryString, "*");

Additionally, regardless of the date format I put in (OA Date, DateTime, raw String, etc.) I can’t get the search to limit my results to what I’m looking for.

1 Like

Yup. Tried that. It doesn’t work.

I think the search feature is broken.

@ufukt51 : I got word from API support. Turns out you need to specify Edmstok_HistoryString as well.

Here’s a working example:

[PDMTestMethod]
            public void GetHistory()
            {
                var now = DateTime.Now.ToOADate();
                var yesterday = DateTime.Today.Subtract(TimeSpan.FromDays(5)).ToOADate();

                IEdmSearch6 search = (IEdmSearch6)(Vault as IEdmVault7).CreateUtility(EdmUtility.EdmUtil_Search);
                search.SetToken(EdmSearchToken.Edmstok_HistoryAfter, yesterday);
                search.SetToken(EdmSearchToken.Edmstok_HistoryBefore, now);
                search.SetToken(EdmSearchToken.Edmstok_FindFiles, true);
                search.SetToken(EdmSearchToken.Edmstok_HistoryString, "%.sldprt");
                var result = search.GetFirstResult();
                while (result != null)
                {
                    var file = Vault.GetObject(result.ObjectType, result.ID) as IEdmFile5;
                    Console.WriteLine($"{file.Name.PadRight(30)} {file.GetLocalFileDate(file.GetParentFolderID())}");
                    result = search.GetNextResult();
                }
            }

2 Likes