I'm working on some C# code that performs tasks based on certain documents. Currently, I'm using Document[] releaseDocs = Document.GetRootDocuments() and then looping through the results.
Is it possible to do something like Document[] releaseDocs = Document.GetRootDocuments().Where(m => m.Published == false); where I could take advantage of the API to only get Published Documents and Documents with certain set Variables? If so, how, because that method doesn't appear to work.
Try something like this:
Document[] documents = Document.GetRootDocuments();
foreach (var doc in documents)
{
// Do Something
}
This should work just fine:
Document[] releaseDocs = Document.GetRootDocuments().Where(m =>
m.Published == false &&
m.getProperty("SomeAlias").Value.Equals("Some Value")).ToArray();
Related
Using the HP-Trim SDK, how do you search for a document by its reference number?
The alleged documentation refers to methods for straightforward searches:
SelectByPrefix
SelectFavorites
SelectByUserLabel
SelectNone
SelectAll
SelectByUris
SelectTopLevels
SelectThoseWithin
and a generic search:
records.SetSearchString(“createdOn:this week and assignee:me”);
but all I want to do is find a document by its index.
These don't work:
records.SetSearchString("recordNum: <RecordNumber>");
records.SetSearchString("recordNumber: <RecordNumber>");
records.SetSearchString("reference: <RecordNumber>");
Any suggestions?
Are you using the .NET SDK? If so you can grab a record by its record number like so (C# example):
using (Database db = new Database()) {
db.Connect();
Record record = new Record(db, "123456"); // Replace with record number
// Do stuff with record
Console.WriteLine(record.Title);
}
You aren't required to construct a 'formal search' as such.
In case you're curious about the correct string search syntax, this would have worked:
records.SetSearchString("number: <RecordNumber>");
Using the COM SDK;
using (Database db = new Database()) {
db.Connect();
Records records = db.MakeRecords();
records.SelectAll();
records.FilterString = "number:<RecordNumber>";
if (records == null || records.Count.Equals(0))
return;
Record existing = records.Item(0);
}
I am working on MVC4 App, and I am stuck at one point, I tried using google to help me, but without success. This might be more simple then I think, but coming from web forms and shifting to mvc is "painful" sometime.
I am trying to loop through the model I have and get the values stored in that model. I tried few approaches but I am getting an error everytime. This is what I have:
var modelAgentFilter = from s in _aa.Agents
where s.COUNTER == Convert.ToInt32(AgentID)
select s;
if (modelAgentFilter != null)
{
ViewBag.FirstName = // Get FirstName object here
}
Thanks in advance for your comments.
Laziale
EDIT:
I did include for loop like this:
if (modelAgentFilter != null)
{
foreach (var property in modelAgentFilter)
{
string test = property.ADDRESS;
}
}
But when the compiler will reach the foreach step I am getting this error: "LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' method, and this method cannot be translated into a store expression."
I can get to the properties of the var model using that foreach look but as soon as the compiler will try to loop the model that error pops up.
Thanks again
LINQ to Entities does not recognize any methods. You can't use even ToString() in LINQ expression. You need first convert your value and than add it in LINQ.
In your example you need to do something like following:
var _agentID = int.Parse(AgentID);
var modelAgentFilter = from s in _aa.Agents
where s.COUNTER == _agentID
select s;
I have searched for quite a while, but I have not found any thread explaining how exactly to find out which Tenant is the current one in code. For example, I want to change some logic based off of what Tenant is active like so:
IQueryable<ContentPartRecord> getContentPartDates;
if (Tenat == ExampleTenant)
{
getContentPartDates = GetContentPartDates((int)Id)
.Where(ss => ss.SalesStatus == "Guaranteed")
.OrderBy(x => x.start_date);
}else {
getContentPartDates = GetContentPartDates((int) Id).OrderBy(x => x.start_date);
}
What exactly is the best way to do this?
Thanks in advance.
Inject ShellSettings in ctor. This object contains all data (from Settings.txt file) about the shell (ie. tenant) in which current unit of work executes.
I have 3 models:
article [name, title]
photo [name, description]
video [name, description, transcription]
Now, I want to create an autocomplete search that will search each of those models and db fields for matching string in the input field.
Is it possible to do a search over these 3 tables?
If so, how would I go about it?
UNION operator is what you're looking for.
I guess your using propel.
Its absolutetly possible to do this, but if these table are not related to anything that could result in some messy code when saving. But if you absolutely need to search in those tables, my approach would be to create an action like:
public function executeAutocomplete(sfWebRequest $request)
{
$q = $request->getParameter('q');//The value to be searched
$limit = $request->getParameter('limit');//Not completly necessary but recommendable
if(count($q) == 0)
{
return sfView::NONE;//With no input, no search
}
$results = array( 'article' => array(), 'photo' => array(), 'video' => array());
$article_search = ArticlePeer::search($q,$limit);
$photo_search = PhotoPeer::search($q,$limit);
$video_search = VideoPeer::search($q,$limit);
$this->process_search($results,$article_search,$photo_search,$video_search);
//Process those three arrays to fit your need
return $this->renderText(json_encode($result));
}
Now, the search function on the Peer classes could look like this:
ArticlePeer>>
public static function search($q,$limit = null)
{
$c = new Criteria();
$c->add(self::NAME,'%'.$q.'%',Criteria::LIKE);
if(!is_null($limit))
{
$c->addLimit($limit);
}
return self::doSelect($c);
}
Finally as for the widget, i have used and adapted sfWidgetJQueryAutocomplete and it work pretty good so you should check it out.
EDIT: The short way to an embbed search field si creating sfForm wit the jQuery widget i mentioned before and leave configuration and js to the widget. You'll have to find a way to handle search resutls.
Well i hope this helped you!
I'm building a Task in Symfony with Doctrine. I'm getting all the places to make a batch update to a particular field. This has to be done in two languages. I'm using setBaseQuery() to make the JOIN on the query with the language I want.
If I do the following in an action, it works without any problem. However, If I do it in a task; it doesn't work as expected. The task runs perfectly two times (one in english and the other in english too!).
Any ideas on what I have to do different on tasks?
thanks!
$languages = array('es' => 'Spanish', 'en' => 'English');
foreach($languages as $lang => $value) {
// get all the places
$q = Doctrine::getTable('Place')
->createQuery('p')
->leftJoin('p.Translation ptr')
->addWhere('ptr.lang = ?', $lang);
$treeObject = Doctrine::getTable('Place')->getTree();
$rootColumnName = $treeObject->getAttribute ( 'rootColumnName' );
$treeObject->setBaseQuery($q);
// all the continents
foreach ( $treeObject->fetchRoots() as $continent ) {
$this->log(date("Y-m-d H:i:s").' '.$lang.' Continent '.$continent->title);
..
}
}
To gain database access in your tasks you'll need to call the following in your execute() method before any other database calls:
$databaseManager = new sfDatabaseManager($this->configuration);
http://www.symfony-project.org/book/1_2/16-Application-Management-Tools#chapter_16_sub_custom_tasks_new_in_symfony_1_1
so the solution I've found is adding $model->Translation[$lang]->title. It's strange because the title should have been loaded through the setbasequery; but it seems not.
// all the continents
foreach ( $treeObject->fetchRoots() as $continent ) {
$this->log(date("Y-m-d H:i:s").' '.$lang.' Continent '.$continent->Translation[$lang]->title);
..
}
Update
I'm getting the translation but $continent->save() didn't save the changes in Spanish (however it's saving it in English). I had to do a manual query in Doctrine:
$con = Doctrine_Manager::getInstance()->connection();
...
$con->execute("update model_translation set field='".$field."' where id='".$model->id."' and lang='".$lang."'");
now everything works...