I have two tables with the following (simplified) structure
person_availabilities (id, person_id)
persons (id)
that are related (a person can have many availabilities)
I have used the bake feature to create the current pages.
What I wish to do is go to a person's profile and click on "New Person Availability". The page will then go to the add person availabilities page and allow the user to input the data there.
The user should not have to find the person in a drop down list, which is the default way to select the identity of the person whose availability I'm setting.
When you go to a person's profile and then navigate to add page, try to pass the id of that person through url to that add page and then try following:
URL may be:
http://example.com/person_availabilities/add/2 // here 2 is the person id
In person_availabilities controller's add function try something like this:
function add($person_id = null) { // $person_id is the passed id. e.g $person_id = 2
$this->set('person_id', $person_id); // set the id to view
}
In view file the select box should automatically show the person whose availability you're using if the select field name is person_id i.e.
$this->Form->input('person_id');
If not then try selected property to that select box:
$this->Form->input('FIELD_NAME', array('selected' => $person_id));
Related
In Salesforce I would like to retrieve AccountIds where its related Contact FirstName must have values in list of String. List of string is {'Test','User'}. I would need to find all Accounts where Contact first Name has both Test and User as related Contacts,
I am trying as below but the below query will show accounts where even 1 value matches as Contact First Name.
List<String> names = new List<String>{'Test','User'}; List<Account> accountList = [ Select Id from Account Where Id IN (Select AccountId FROM Contacts where FirstName LIKE :names)];
Please help
SELECT Id, Name
FROM Account
WHERE Id IN (SELECT AccountId FROM Contact WHERE LastName = 'Test')
AND Id IN (SELECT AccountId FROM Contact WHERE LastName = 'User')
But it'll work only 2 times, you can't write 3rd "IN" like that (see here).
If you need a more generic solution that can take lists of any size you'd have to run "my" queries in loop, 2 names at a time, save results to some Set<Id> or Map, play with functions like myset.retainAll(idsFromCurrentLoopQuery)... Of course query in a loop is bit evil too.
Afternoon,
I am gathering data from the LiveChatTranscript and there are multiple references to user as lookup fields. How do I pick which property I want to use as my reference to user?
LiveChatTranscript properties
LastModifiedById Lookup(User)
CreatedById Lookup(User)
OwnerId Lookup(User,Group)
query
-webroot-/query/?q=select chatkey, caseid, status,requesttime, starttime, endtime,endedby,name,ReferrerUri,platform,location, waittime,body,supervisortranscriptbody, case.description, ownerid,ownerid.user.alias?? from livechattranscript where chatkey = '12345'
In this case, owner is the field name. It looks up to the user object. No need to include the object name there. Just drop the id potion for ownerid.
Use owner.alias.
I create a Employee object where I want to show Lookup Relationship field for Lead. Employee records are coping from Lead. so how to do ?
Actully I wrote in class,
emp.Source_Lead__c = lead.id; // emp is Employee object & lead is Lead object.
but it shows me Name, CompanyName in lookup so it wont access.
like :
Source Lead : eabc exyz, ecompany
Help me....
If you're talking about new employee / edit employee form - yes, you pass an Id. You're doing it right. The tricky part is that you can't immediately use "dots" to show fields from Lead.
After establishing the link and saving you will have to query for lead fields. Something like this (your question isn't too clear, I don't know if this is on one page or 2).
Employee__c emp = new Employee__c();
// ... fill fields as needed
emp.Source_Lead__c = lead.Id;
insert emp;
// And later you can query
emp = [SELECT Id, Name, Source_Lead__c, Source_Lead__r.Name, Source_Lead__r.Custom_Field__c
FROM Employee__c WHERE Id = :emp.Id];
System.debug(emp.Lead_Source__r.Name); // now it will work
I have two tables, user and company, and I have a combo box in which I list all the companies I have in the company table. My question is, how to use databinding in foxpro to display the company name? When I save the information to the database, I only need to save the company ID; same for display, from the company ID I have in my user table, I would like to display the company name.
I tried using the properties :
CmbCompany.controlesource = myTable.companyID
cmbCompany.displaysource = myTable.companyName
but this doesn't work, I missing something!
Set the RowSource for the combo so that it puts the data you want to show in the first column, and the value you want to store in the second. Set BoundColumn to 2 and, if your ID field is numeric or integer, set BoundTo to .T.
I'd do all this in the property sheet, but something like this:
RowSourceType = 6-Fields
RowSource = Company.CompanyName, ID
BoundColumn = 2
BoundTo = .T.
ControlSource = MyTable.CompanyID
Tamar
I have an object named 'Salary'. There are three fields in it- 'Add Salary', 'Month' and 'Available Salary'. Also there is a lookup relationship from Salary object to 'User Name' object. For every user there is a salary record for every month. Whenever salary is added to a particular user's record, the available salary should show the sum of salaries of previous months. How can I do that?? Please suggest me....Thanks.
The easiest way would be to change the Lookup Relationship to a Master-Detail Relationship and use a Roll-Up Summary field on the User object (Setup > Customize > Users > Fields > User Custom Fields > New).
Alternatively, you could use a Trigger on the Salary object, but only do that if you absolutely need additional functionality that cannot be accomplished with a Roll-Up Summary or other configuration.
Here's an example of using a Trigger. I haven't tried compiling it, so there will inevitably be some compile errors, but it's a place to start.
trigger AddSalary on Salary__c (after update) {
// create a set of all the unique User Ids
Map<Id,List<Salary__c>> SalaryByUserId = new Map<Id,List<Salary__c>>();
for(Salary__c s : Trigger.new)
{
List<Salary__c> SalariesForUser = SalaryByUserId.get(s.User__c);
if(SalariesForUser == null)
{
SalaryByUserId.put(s.User__c,new Salary__c[]{s});
}
else
{
SalariesForUser.add(s);
SalaryByUserId.put(s.User__c,SalariesForUser);
}
}
// query for all the User records for the unique UserIds in the records
// create a map for a lookup / hash table for the User info
Map<Id,User> Users = new Map<Id,User>(
[Select Id, Username, Available_Salary__c From User Where Id IN SalaryByUserId.keyset()]);
// iterate over the list of records being processed in the Trigger and add the Salaries to the Users
for (Id i : SalaryByUserId.keyset())
{
User u = Users.get(i);
Decimal TotalSalary = 0;
for(Salary__c s : SalaryByUserId.get(u.Id))
{
TotalSalary += s.Monthly_Salary__c;
}
Users.get(u.Id).Total_Salary__c = TotalSalary;
}
update Users;
}