How to add or set value for "Department" field in google contacts?
No problems with "Company" and "Job title"
var contact = ContactsApp.createContact('John', 'Doe', 'john.doe#example.com');
var company_set = contact.addCompany('Google', 'Product Manager');
// ?????
var department_set = contact.add______________('IT');
UPD: Thanks to #TheMaster I've managed to solve this task.
Nice API example you can find here https://www.any-api.com/googleapis_com/people/docs/people/people_people_createContact
Using the examle on this site you can build required body for API.
var reqBody = {
names: [
{
givenName: givenName,
familyName: familyName
}
],
phoneNumbers: phoneNumbers,
organizations: [
{
title: orgTitle,
department: orgDepartment
}
],
emailAddresses: [
{
value: emailAddres,
type: 'work'
}
],
addresses: [
{
city: city,
streetAddress: streetAddress,
type: 'work'
}
],
memberships: [
{
contactGroupMembership: {
contactGroupId: contactGroupsID,
contactGroupResourceName: "contactGroups/" + contactGroupsID
}
}
]
}
createContact(reqBody);
It is possible to set department through People API with Advanced Google services. When a contact is created through the api, the people object can include organizations[].department
Related
I need to create a new group "Carpenters" (if the group doesn't exist) and add the created contact to "Carpenters" group
I have tried with
function doGet(e) {
var id = People.People.createContact(
{
"names": [
{
"displayNameLastFirst": "Smith Jefferson Jones",
"familyName": "Jones",
}
],
/* "phoneNumbers": [
{
'value': "+12345679962"
}
],
"emailAddresses": [
{
'value': ' '
}
]*/
}
).metadata.sources[0].id;
return ContentService.createTextOutput("Success");
}
You could do the following:
Retrieve the resourceName of the created contact (to be used on step 4).
Check if the group exists by listing all contactGroups and looking for a group whose name is Carpenters (using find()).
Create a contactGroup called Carpenters if it doesn't exist, using contactGroups.create.
Use contactGroups.members.modify to add the created contact to the group.
Code sample:
function doGet(e) {
// 1. CREATE CONTACT:
var contactResource = {
"names": [{
"displayNameLastFirst": "Smith Jefferson Jones",
"familyName": "Jones",
}],
/* "phoneNumbers": [{
'value': "+12345679962"
}],
"emailAddresses": [{
'value': ' '
}]*/
}
var contactResourceName = People.People.createContact(contactResource)["resourceName"];
// 2. CHECK IF GROUP EXISTS:
var groupName = "Carpenters";
var groups = People.ContactGroups.list()["contactGroups"];
var group = groups.find(group => group["name"] === groupName);
// 3. CREATE GROUP IF DOESN'T EXIST:
if (!group) {
var groupResource = {
contactGroup: {
name: groupName
}
}
group = People.ContactGroups.create(groupResource);
}
var groupResourceName = group["resourceName"];
// 4. ADD CONTACT TO GROUP:
var membersResource = {
"resourceNamesToAdd": [
contactResourceName
]
}
People.ContactGroups.Members.modify(membersResource, groupResourceName);
return ContentService.createTextOutput("Success");
}
Reference:
contactGroups.members.modify
I have a airports table with every row containing following fields: IATA, city, country... How can I search for all of these fields but return the results with the exact match first? For example if I type ALB, I want to see first result as ALB, Albany, USA and then all other matches rather than TIA, Tirana, Albania and Albany after that?
Here is my code:
const airports = await Airport.findAll({
attributes: [
'IATA',
'city',
'country',
],
where: {
[sequelize.Op.or]: [
{ IATA: filter.toUpperCase() },
{ city: { [sequelize.Op.like]: `%${filter}%` } },
{ country: { [sequelize.Op.like]: `%${filter}%` } },
],
status: 1,
},
});
I solved a related problem with this approach. I created a column on order that returns 1 if is a exact match on IATA like else 2. Ordering this column will solve your problem.
As your column could be different and using literal(), you may adapt the order property but the concept is this.
const airports = await Airport.findAll({
attributes: [
'IATA',
'city',
'country',
],
where: {
[sequelize.Op.or]: [
{ IATA: filter.toUpperCase() },
{ city: { [sequelize.Op.like]: `%${filter}%` } },
{ country: { [sequelize.Op.like]: `%${filter}%` } },
],
status: 1,
},
order: {
[
sequelize.literal('CASE WHEN `IATA` like '%${filter}%' THEN 1 ELSE 2 END',
'desc'
],
['city', 'desc']
}
});
In my purpose, I got 4 CASEs and worked very well.
Obs: If your model have alias on column IATA, here, you need to put your original column name, as we building an literal term.
I have been using the ng2-smart-table template. I could not able to found the location where the data save after click the add new button.some one can help me now.
In this table create data and show in the list the data what we are created. but the case is if we are refresh the browser , the above mentioned data not saved. then what should i do for add those data for firestore.
The DataSource of the mentioned module is simply an array or LocalDataSource object according to Documentation.
Let's take an example.
On typescript file define an array like this.
data = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere#april.biz"
},
{
id: 2,
name: "Ervin Howell",
username: "Antonette",
email: "Shanna#melissa.tv"
},
// ... list of items
{
id: 11,
name: "Nicholas DuBuque",
username: "Nicholas.Stanton",
email: "Rey.Padberg#rosamond.biz"
}
];
settings = {
columns: {
id: {
title: 'ID'
},
name: {
title: 'Full Name'
},
username: {
title: 'User Name'
},
email: {
title: 'Email'
}
},
add:{
confirmCreate:true
},
mode:'inline'
};
On template(html).
<ng2-smart-table (createConfirm)="addData($event)" [settings]="settings"
[source]="data"></ng2-smart-table>
Again on template.
addData(event){
//event.data is the newely created data
// Handle newly created data
// Shape of object is {
// id,
// name,
// username,
// email,
// }
// You must call event.confirm.resolve() to show data on table
}
Above addData(event) function is called when click ctrate confim.
I'm programming a function in order to update users' info. I did it and it works fine however it doesn't work when I want to use custom schemas. I checked the reference but it showed an error "Invalid Input: [employmentData] "
function directoryUpdate(userId, userDept, userLocation, userPhone,userTitle) {
var userId = 'devtest#pruebatest.com',userDept='D003', userLocation='L003';
var userTitle='T003';
var update = {
ims:
[{
type: "work",
protocol: "gtalk",
im: "liz_im#talk.example.com",
primary: true
}],
emails: [
{
address: "liz#example.com",
type: "home",
customType: "",
primary: true
}
],
addresses:
[{
type: "home",
customType: "",
streetAddress: "1600 Amphitheatre Parkway",
locality: "Mountain View",
region: "CA",
postalCode: "94043"
}
],
organizations:
[{
name: "Next Step",
title: userTitle,
primary: true,
type: "work",
department: userDept,
location: userLocation
}],
customSchemas: {
employmentData: {
employeeNumber: "123456789",
jobFamily: "Engineering",
location: "Atlanta",
jobLevel: 8,
projects: [
{ value: "GeneGnome", customType: "development" },
{ value: "Panopticon", customType: "support" }
]
}
}
};
update = AdminDirectory.Users.patch(update, userId);
Logger.log('User %s updated with result %s.', userId, update)
return true;
}
What's the error?
Greetings, Thanks in advance.
The employmentData field is inside the "customSchemas" field. Custom schemas have to be defined before using them.
To create a Custom Schema you have to use the resource Schemas.insert.
After creating the schema with the correspondent fields and type of value (STRING, INT, ETC) your code should run without issues. I tried it and worked for me.
Also, after updating the user, when making the call to Users.get, you have to set the parameter "projection=full" in order to see these values in the response.
I am trying to update user's reach profile attributes with below apps script. It is updating all fields except only addresses. Kindly suggest if I am missing anything. Below is the part of code:
var resource = {
organizations:
[{title: designation,
department: department,
}],
addresses: [
{
locality: "Pune",
streetAddress:"Kothrud",
postalCode:"411038",
primary:true,
region:"Maharashtra",
type: "work",
}
],
phones: [{
type: "work",
value: phone,
},
{
type: "mobile",
value: mobile,
},
{
customType: "Extension",
value: land_line,
},
{
customType:"Middle Name",
value: middle,
}],
}
var result = AdminDirectory.Users.update(resource, email_address)
Instead of update you could try result = AdminDirectory.Users.patch(resource, userId);
API link for your reference here.
Hope that helps!