Retrieving two records with the same name - soap

I have to get two different names pulled from this query, the Account Name and the Opportunity Name. Both are called "Name" under each object.
I am able to use a query to retrieve both of them, but I am unable to decipher between the two in order to actually echo/print or use them.
My Query is:
$query = "SELECT Name,Opportunity.Account.Name from Opportunity ";
$response = $mySforceConnection->query($query);
foreach ($response->records as $record) {
echo $record->Name ."<br/>\n";
//echo $record->Opportunity.Account.Name ."<br/>\n";
echo "<br/>\n"; }
The only Name that is displayed is the opportunity Name (when trying different methods, I know the code above will only echo that)
I have made two seperate queries one from account and one from opportunity to ensure both are infact different things, and they are.
I have attempted to echo two "Name" records, both are just the opportunity name it doesn't recognize the account name.
And obviously what is commented out above as "Opportunity.Account.Name" isn't echoing the result, i am recieving an error instead.
I know using an alias is not supported in salesforce so that obviously didn't and won't work, by that I mean trying to do this:
Select Name as OppName
I am unable to find a different way to echo the records, I have done a lot of googling on the subject. Any help would be appreciated or a point in the right direction.

In my schema there is no Name field in the Opportunity object. There is Account Name and it is a lookup on Account Name in the Account object. You can view the schema builder by going to Setup > Schema Builder (it is under App Setup).

To be honest, I don't know why this worked. I'm new to SOAP and Salesforce, so I was just trying different things to get it working. But if anyone else has this problem, this is how I fixed it.
I displayed the account name by using this to echo it:
echo $record->Account->Name ;
The query is still the same as in the question.

Related

What is the correct way to express "select all when nothing is specified in parameter"?

Let's say we have an HTTP endpoint to get all elements by name?
GET /elements?name={name}
{name} can have a value of CSV or be absent
valid:
GET /elements?name=Bill,Mary,Ann
GET /elements?name=Mike
GET /elements
invalid:
GET /elements?name=
Somehow we find out in controller that name is not passed. We know that the contract implies to return all values for elements. Possible decisions on further actions (I've seen in different projects) are:
using a NULL or a "dummy" substitution like a secret char sequence "!#$#%#$" and juggling them in database while building a query
using if (present) { executeQueryA } else { executeQueryB } logic
I am not sure I like either of these approaches, because when there is more than one optional filter these designs become unmaintainable. Something makes me believe that there is a better way to handle the situation.
What would be a proper design on back-end and in database query to handle the case "select all" when nothing is given? Just a general idea and some pseudo-code will be much appreciated.

Getting the user's name without directly asking for it (Watson Assistant)

I'm creating a chatbot for fun and want to implement something to collect the user's name, but only if he says something like "my name is ..." or close to that; the intention of giving the name would come from the user, the bot won't ask for it, maybe only suggest it. Kind of like in Google Assistant, I think. So, it could be given at any time the user wants.
My idea is:
1st create an intent with different ways the user would tell his name to the bot (like in the example above).
2nd use slots and, if the intent is detected, save it as a variable. So far, I've managed.
3rd is the part that I'm stuck in, since it's only an idea and I don't know how I'd do it. Before saving the whole text as a variable, I'd like to delete the part that's included in the intent (my name is) and save only the rest in the variable. So, for example, the user says "my name is XXX"; the command deletes the "my name is" part and saves only "XXX" in the $name intent.
I don't know if this'd be possible, since I don't know coding. I used some special syntax before, like to capitalize the first letter of some other variable, but I don't really know how to use the JSON editor.
Is my idea viable? I don't know how I'd delete the intent corresponding portion and save only the remaining part as the intent. Dunno what would be the command for that, nor where I'd write it.
You can suggest something else if you have an idea.
Last thing, I'm created the skill in portuguese, so there's no access to the #sys-person entity.
Thanks for reading.
I use portuguese skills and face the same issue. I see two solutions, althougt they are not perfect:
Using intents:
When the intent is identified, the bot asks the name again, telling the user that he should only say his name, e.g without "my name is", then store the whole input on a context variable, using:
<? input.text ?>
For embedding such logic inside slots, you probaly will need to use digressions.
But, this is boring to the user.
Using entities:
Entities identification carries along they start and end position in the input text, but intents not. With this, is possible to slice the input, cutting the entity:
<? input.text.substring(entities.name.location[1], input.text.length()) ?>
Entites would be "My name is", "People call me", "I'm called", "I'm baptized", "I was baptized".
So, "Hello, my name is Gustavo", would be cut after "my name is" ending, resulting in "Gustavo". Additional input in the beggining is ignored, but problems arrise with additional input after the name. Also, you need to define more "my name is" like entities, likely all possibilities, than would need if using intents, cause even with fuzzy matching, entities identification doesn't take in account synonymus and similar meaning words.
https://cloud.ibm.com/docs/assistant?topic=assistant-dialog-methods#dialog-methods-strings-substring
https://cloud.ibm.com/docs/assistant?topic=assistant-expression-language#expression-language-access-entity

SharePoint REST: Column does not exist error

I'm calling a REST API with a SharePoint Designer workflow on SharePoint online. I'm setting the column name with a variable, and when i put the variable into my URL to call it it says "Column [name] does not exist".
Annoying part is when I call just /items? I can see the column in the result, but if I try select it or filter by it I get 'does not exist'. I have alot of these columns similarly named, and I get the error for all of them.
I am using the internal name, I have tried adding "OData_" to the front. I've tried typing the url manually in the browser and entering values (incase the variable was causing issues) but I get the same error, column does not exist. but i can see it them I call all items. :(
so I have quite a few columns with naming convention "[Q#] Score [#]" eg "Q4 Score 2". The internal name that's clearly appearing in the full items results is "Q4_x0020_Score_x0020_2".
This works:
https://MYSITE.sharepoint.com/sites/portal/intranet/CorpServices/QSR/_api/web/lists/GetbyTitle('Audit')/Items?
and I get big full normal REST results that includes the line:
0
However if I try:
https://MYSITE.sharepoint.com/sites/portal/intranet/CorpServices/QSR/_api/web/lists/GetbyTitle('Audit')/Items?$Select=Q4_x0020_Score_x0020_2
Then I get:
-2146232832, Microsoft.SharePoint.SPExceptionColumn 'Q4_x0020_Score_x0020_2' does not exist. It may have been deleted by another user.
I expect to be able to select that column (and the dozens like it) but none work. I've searched all similar problems on the forum and they've usually got a spelling mistake or forgot the ODATA_ but i cant seem to get the problem. Please help.
It seemed to be working intermittently.... So it was in fact just a naming error...... Half of the columns were [Q#]_x0020_Score_x0020_[#] and half were [Q#]_x0020_score_x0020_[#]. The word "Score" was capitalized on some and not others. I Didn't realize the HTTP Calls were case sensitive. Now I have added a bunch of if statements to handle the different variations haha. Thanks for reading.
Judging by the naming convention you are on an older version of SharePoint. The x0020 is the value for a space. Ideally when you first create the column you would name it without the spacing. For example UserInformation. Then come in and edit the name after the fact and call it User Information. If you click on the title name and look at the URL, you will see what the actual name of the column is at the end of the URL. It is case sensitive because you can have a column named score and Score which is ultimately why it wasn't working.
Must load all fields like this
var lists = context.Web.Lists;
context.Load(lists);
context.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml = #"";
var list = lists.GetById("file.guid");
var listitems = list.GetItems(query);
context.Load(listitems);
context.ExecuteQuery();
var creationInformation = new ListItemCreationInformation();
var newItem=list.AddItem(creationInformation);
var fields = list.Fields;
context.Load(fields);
context.ExecuteQuery();

How to add a custom column to OTRS ticket view (dashboard)

I've been trying to append some more data to an OTRS ticket (newest version). And I have managed to get the information in the ticket data alright, however, I do not know how to access it in the view. Most data seems to be parsed through via $QData/$Data, however, all I get when I print my variable is 16/12.
%CustomerCompanyName = $Self->{CustomerCompanyObject}->CustomerCompanyGet( CustomerID => $Ticket{CustomerID} );
#}
$Ticket{CustomerCompanyName} = \%CustomerCompanyName;
And I want to access it in the dtl AgentDashboardTicketGeneric.dtl, however, $Data{"CustomerCompanyName"} is empty. I've managed to get the hash or 16/12 out. Again, in the variable $Ticket we've managed to dump the variable and see the data is actually in there (without actually being able to access it, we can't figure out which data type it is and have tried all possible ways we could think of).
Edit: I figured it out. It worked with Johannes solution, however, the value of the column in the SysConfig had to be 2, and not 1.
you can access all Ticket Data through the User Interface. In every widget, in the top right corner you can access the settings and remove, add, sort columns.
If you need the Customer Company data, which are not bound to the ticket-data, then you need to modify / extend the given module (Kernel::Output::HTML::DashboardTicketGeneric). Thats the reason why $Data{"CustomerCompanyName"} is empty, because the customer company stuff is not loaded there.
IMHO you don't need to modify the dtl. Add the new column in the sysconfig:
HTTP://OTRSHOST/otrs/index.pl?Action=AdminSysConfig;Subaction=Edit;SysConfigSubGroup=Frontend%3A%3AAgent%3A%3ADashboard;SysConfigGroup=Ticket
Add the new Column "CompanyName" to every widgets DefaultColumns.
(Hint: here you can also add DynamicFields using DynamicField_XXX)
Then modify the Code in DashboardTicketGeneric.pm
First: add the module (around L:21)
use Kernel::System::CustomerCompany;
after that initiate the module (after CustomerUserObject around L: 44)
$Self->{CustomerCompanyObject} = Kernel::System::CustomerCompany->new(%Param);
Then add the logic to the module (around L: 1414 - after the customer name block:
elsif ( $Column eq 'CompanyName' ) {
# get customer company name
my %CompanyData;
if ( $Ticket{CustomerID} ) {
%CompanyData = $Self->{CustomerCompanyObject}->CustomerCompanyGet(
CustomerID => $Ticket{CustomerID},
);
}
$DataValue = $CompanyData{CustomerCompanyName};
}
Then delete the cache (..bin/otrs.DeleteCache.pl), because widgets use caching and your changes won't apply fast enough ;)
Add the column to your widget (top right corner in the widget -> Settings) and you should be fine.
Update: place the "new Module" in the custom folder
Custom/Kernel/Output/HTML/DashboardTicketGeneric.pm
regards
Johannes

How can I display count of imagefield images in views?

I want to display the number of images uploaded to an imagefield, in a views field or views tpl.php. How can I do this? My imagefield is called boatimages. I tried this but it comes out as 0, not the correct number: < ? php print count($fields->field_boatimages) ?>
Ack. I do not think count() works like that.
Why not just do this using Views? Take a look at Arguments > Settings and you'll see 'display record count' which seems like all you would need for this.
My suggestion is install the devel module and use the function dpm to print the variable if you wanna know the structure (print_r() may work too). If count isn't working it's because, you are probably using it with the wrong data.
OR, you could just query the database for the field. I'm gonna provide you instructions for drupal 7 but drupal 6 should be similar.
Check the table field_data_field_boatimages. See how there's a list of your images related with a single entity_id
Then execute this query
SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = ###
Where ### is the entity_id you want to know. You can get it by looking for arg(1) if arg(0) == node in your page.
Now you just have to use php power to print thar result
$query = SELECT COUNT(*) FROM `field_data_field_boatimages` WHERE entity_id = :eid
$result = db_query($query, array(':eid', $nid))->fetchField();
echo $result;
Drupal 6 would be very similar. Just a little difference in the table names and the query syntax. For example using db_result instead of fetchField()
Anyway good luck!