cancel
Showing results for 
Search instead for 
Did you mean: 

Restoring NamedSearch with Java API

martin_schffler
Participant
0 Kudos

Hi,

I tried to restore a NamedSearch with the following code:


    RestoreNamedSearchCommand restoreNamedSearchCommand = new RestoreNamedSearchCommand(context);
    restoreNamedSearchCommand.setSession(session);
    restoreNamedSearchCommand.setTableId(namedSearchTableId);
    restoreNamedSearchCommand.setRecordId(searchRecord.getId());
    restoreNamedSearchCommand.execute();
    Search namedSearch = restoreNamedSearchCommand.getSearch();

But I always get the following error: Server error (0xffaa0310)

No matter which NamedSearch I try to read.

Has anybody encountered that error before and knows what it means?

Or has someone succesfully restored a NamedSearch via the Java API?

Many thanks,

Martin

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Martin,

Here is a quote from the MDM API JavaDoc:

A command to restore a named search. A named search is a search criteria that has been saved.

Note: Not all named search can be restored by the API.

It seems you may be in one of those occasions where the named search cannot be restored.

There is, fortunately a workaround. The following piece of code will add a named search to an MDM Search object, and will always work in returning the correct records when used in a RetrieveLimitedRecordsCommand (or any other command that takes a search object).


// Step 1: Create a SearchDimension
SearchDimension sd = new NamedSearchSearchDimension();\

// Step 2: Create an array of MdmValue and add the NamedSearch ID to the array
MdmValue [] mdmValues = new MdmValue[1];
mdmValues[0] = new LookupValue(new RecordId(namedSearchId));

// Step 3: Create a PicklistSearchConstraint and add the array of lookup values
PicklistSearchConstraint sc  = new PicklistSearchConstraint(mdmValues);

// Step 4: (Optional, but advised) Create a SearchParameter
SearchParameter sp = new SearchParameter(sd, sc);

// Step 5: If you do not already have a search object, create a new one
Search search = new Search( mainTableId );

// Step 6: Add the search parameter to the search
search.add( sp );

// Now use the search in a retrieve command 

Hoping this solves your problem,

Walter

martin_schffler
Participant
0 Kudos

Hi Walter,

Thanks for the answer.

Sadly that only solves part of my problem.

I actually wanted to add search constraints to the named search and then save it again, but I couldn't find a way to save the named search anyway (at least not in the public part of the API); like 'STORE_QUERY' in the ABAP API.

I read the warning in the Javadoc, that not all named searches can be restored via the API, but I yet have to find a search that can be restored. Have you successfully restored a search using the API? And if so how did the search look like?

I tried with simple searches: only one lookup value or only one text search. But it didn't work with any of those Searches.

btw. have you (or anybody else) used the internal classes of the API for some functionality?

I have looked into some of the classes and it seems there are a few things that are supported in the internal classes but are not exposed in the API.

Of course there will be no support for doing something like this and one has to be careful with updates of the API, but are there any other reasons not to use the internal classes?

Thanks,

Martin

Former Member
0 Kudos

Hi Martin,

You are correct that there is no way via the API to create or update named searches. You can use the serialize() and deserialize() methods of the Search object to, say, reconstruct the search in a second application, but this is only for immediate use, since if any lookup values are part of the search it cannot be guaranteed that the lookup ID's will exist at any future time.

As for RestoreNamedSearchCommand not working, please open a ticket via the normal channel for this.

Regarding the use of internal classes or methods, I would strongly recommend against doing this, since they may disappear or change at any time, and any applications you have written using them will be broken.

Regards,

Walter