I am importing users to Google Suite from a Google sheet using Google Apps Script. I have made "custom attributes" in Google Admin Console, some of them are set to type email. Everything works great except when one user lack those email addresses.
My users are kids, and the emailaddresses are to the kid's parents. One kid might have 1 parent and 1 email. Other kids have 4 parents and 4 emails.
If all variables (epost1, epost2, epost3 and epost4) are filled with email-addresses the user is added. If one of the variables are empty, the script stops with the following message:
GoogleJsonResponseException: API call to directory.users.insert failed
with error: Invalid Input: custom_schema (line 272, file
"nyeMedlemmer")
I tried to put an if-statement in the code, but that was not possible. Is there a way I can tell the script to just ignore those errors?
My code (after the variables are set):
var user = {
primaryEmail: epost,
name: {
givenName: fmnavn,
familyName: etternavn
},
addresses: [
{
type: "home",
formatted: adr
},
{
type: "other",
formatted: adr2
},
{
type: "home",
postalCode: postnr
}
],
phones: [
{
value: mobil,
type: "home"
}
],
emails: [
{
address: epostPriv,
type: "home"
}
],
recoveryEmail: epost1,
locations: [
{
floorName: grad,
type: "desk",
area: "desk"
}
],
gender: {
type: kjonn
},
orgUnitPath: "/Speidere/Stifinnere/"+tropp,
customSchemas: {
Personlig_informasjon: {
skole: skolen,
hensyn: hensynet,
bursdag: dato
},
Innmeldingssvar: {
hjelpe_til: hjelpen,
teste: testen,
merknad: merknaden,
bilde: bildet,
samtykke: samtykket,
innmeldingsdato: innmeldingsdatoen
},
Foresatt: {
foresatt_navn: [
{
value: navn1
},
{
value: navn2,
},
{
value: navn3
},
{
value: navn4
}
],
foresatt_epost: [
{
value: epost1
},
{
value: epost2
},
{
value: epost3
},
{
value: epost4
}
],
foresatt_mob: [
{
value: mobil1
},
{
value: mobil2
},
{
value: mobil3
},
{
value: mobil4
}
]
},//foresatt
},//CustomSchemas
password: passord
}; //var user
user = AdminDirectory.Users.insert(user);
Sometimes all I need is a little break away from the code... I suddenly dawned on my that I could do the if earlier in code:
var epostForesatt = "{value:"+ epost1+"}";
if (epost2 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost2+"}";
}
if (epost3 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost3+"}";
}
if (epost4 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost4+"}";
}
And then later in, down in "var user customSchemas" I edit the code to to use this variable.
Foresatt: {
foresatt_navn: [
{
value: navn1
},
{
value: navn2,
},
{
value: navn3
},
{
value: navn4
}
],
foresatt_epost: [epostForesatt],
Related
I am trying to create a database using notion sdk and in this is what my payload looks like:
parent: {
type: "page_id",
page_id: process.env.PAGE_ID,
},
icon: {
type: "emoji",
emoji: "🐽",
},
title: [
{
type: "text",
text: {
content: "DB Title",
},
},
],
properties: {
"Prop-1": {
date: {},
},
"Prop-2": {
multi_select: {
options: [
{
name: "option-1",
color: "green",
},
{
name: "option-2",
color: "gray",
},
{
name: "option-3",
color: "pink",
},
],
},
},
"prop-3": {
multi_select: {
options: [],
},
},
},
I have already added title which can be seen above however the response give 400 status code.
#notionhq/client warn: request fail { code: 'validation_error', message: 'Title is not provided' }
Can't figure our where am I going wrong.
You also need to add a title column to your properties. Look at the example payload in the docs, you will see a "Name" title column.
https://developers.notion.com/reference/create-a-database
let object=
[
{
id:`01`,
name:`fish`,
type:null,
care:'owner',
},
{
id:`02`,
name:`fish`,
type:'fresh',
care:'peter',
},
{
id:`03`,
name:`fish`,
type:`fresh`,
care:'amy',
},
{
id:`04`,
name:`fish`,
type:`tank`,
care:'abc',
},
{
id:`05`,
name:`animal`,
type:`pet`,
care:'teen',
},,
{
id:`06`,
name:`animal`,
type:`pet`,
care:'ran',
},
{
id:`07`,
name:`animal`,
type:null,
care:'roh',
},
{
id:`08`,
name:`food`,
type:`veg`,
care:'test',
},
{
id:`09`,
name:`food`,
type:null,
care:'dop',
}
]
object.map((value)=>{
console.log(value.name)
// i am calling function here by passing value.name as a parameter
let gotValue = functionName(value.name);
// using type also
if(typeof value.type!=="string"){
// Do some task here with gotValue
}
})
I have this object and i am getting some value from it for ex getting name from it as i want to pass this name to function but the problem is due to repeat of data the function calling again and again is there any possibility i can run function inside map but with unique value any help ?
as my output is getting like this
fish
fish
fish
animal
animal
animal
and this value.name is passing inside my function so its repeating like this
functionName(fish);
functionName(fish);
functionName(fish);
functionName(animal);
functionName(animal);
functionName(animal);
multiple time function is running with same name and getting duplicate values
just need my function run with unique name
functionName(fish)
functionName(animal);
functionName(food);
as i want to stay inside map function because i am performing some task which can only be possible inside map that's why i need unique value
You can use Set which can be used to test if the object with value already exists or not. It will only call the function only once.
let object = [
{
id: `01`,
name: `fish`,
type: null,
},
{
id: `02`,
name: `fish`,
type: `fresh`,
},
{
id: `03`,
name: `fish`,
type: `tank`,
},
{
id: `04`,
name: `animal`,
type: `pet`,
},
{
id: `05`,
name: `animal`,
type: `wild`,
},
{
id: `06`,
name: `animal`,
type: null,
},
{
id: `07`,
name: `food`,
type: `veg`,
},
{
id: `08`,
name: `food`,
type: null,
},
];
const dict = new Set();
object.map((value) => {
if (!dict.has(value.name)) { // Run only if objet with name is not already existed in dict
dict.add(value.name);
console.log(value.name); // For testing
// functionName(value.name);
}
});
If you want to call the function with two filters then you can use some to find the elements in an array. See I've now declared dict as an array
let object = [{
id: `01`,
name: `fish`,
type: null,
},
{
id: `02`,
name: `fish`,
type: `fresh`,
},
{
id: `03`,
name: `fish`,
type: `tank`,
},
{
id: `04`,
name: `animal`,
type: `pet`,
},
{
id: `05`,
name: `animal`,
type: `wild`,
},
{
id: `06`,
name: `animal`,
type: null,
},
{
id: `07`,
name: `food`,
type: `veg`,
},
{
id: `08`,
name: `food`,
type: null,
},
{
id: `09`,
name: `food`,
type: null,
},
{
id: `10`,
name: `fish`,
type: `tank`,
},
];
const dict = [];
object.map((value) => {
const { name, type } = value;
if (!dict.some((obj) => obj.name === name && obj.type === type)) {
// Run only if objet with name is not already existed in dict
dict.push({ name, type });
console.log(name, type); // For testing
// functionName(value.name);
}
});
.as-console-wrapper { max-height: 100% !important; top: 0; }
I was wondering if anybody could help me out with an explanation as to why the below code would cause the command line to exit without waiting for an answer from the user.
init();
function init() {
loadPrompts();
}
async function loadPrompts() {
const { choice } = await inquirer.prompt([
{
type: "list",
name: "choice",
message: "What would you like to do?",
choices: [
{
name: "View All Employees",
value: "VIEW_EMPLOYEES",
},
{
name: "View All Employees By Department",
value: "VIEW_EMPLOYEES_BY_DEPARTMENT",
},
{
name: "View All Employees By Manager",
value: "VIEW_EMPLOYEES_BY_MANAGER",
},
{
name: "Add Employee",
value: "ADD_EMPLOYEE",
},
{
name: "Remove Employee",
value: "REMOVE_EMPLOYEE",
},
{
name: "Update Employee Role",
value: "UPDATE_EMPLOYEE_ROLE",
},
{
name: "Update Employee Manager",
value: "UPDATE_EMPLOYEE_MANAGER",
},
{
name: "View All Roles",
value: "VIEW_ROLES",
},
{
name: "Add Role",
value: "ADD_ROLE",
},
{
name: "Remove Role",
value: "REMOVE_ROLE",
},
{
name: "View All Departments",
value: "VIEW_DEPARTMENTS",
},
{
name: "Add Department",
value: "ADD_DEPARTMENT",
},
{
name: "Remove Department",
value: "REMOVE_DEPARTMENT",
},
{
name: "Quit",
value: "QUIT",
},
],
},
]);
switch (choice) {
case "VIEW_EMPLOYEES":
return viewEmployees();
default:
return quit();
}
}
async function viewEmployees() {
const employees = await db.findAllEmployees();
console.table(employees);
loadPrompts();
}
The aim is a simple command-line application that asks the user to select an option - then depending on what they have selected a function will be executed. But what is happening is that the application is running, showing the options then immediately exiting...
You Should use await with loadPrompts() to work synchronously;
(async function init(){
await loadPrompts();
})();
I have the below tracking script loading on my site. I want to return "checkout_date" value for GTM purposes. Function will be run through GTM.
Once i have the correct return fucntion js i can implement. I've tried a few things found here but all of them seem to require "var name =" which i don't see present anywhere.
For example, i have tried the below with no success:
function (for(checkout_date in window.hTaxis.criteoBasketTag)) {
if(window.hTaxis.criteoBasketTag.hasOwnProperty(checkout_date)) {
return "checkout_date" = data[checkout_date];
//do something with value;
}
}
<script type="text/javascript">
window.hTaxis = window.hTaxis || {};
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{ event: "setAccount", account: 31165 },
{ event: "setSiteType", type: window.hTaxis.siteType },
{ event: "setHashedEmail", email: "" },
{ event: "viewItem", item: 1016454 },
{
event: "viewSearch",
checkin_date: "2020-01-31",
checkout_date: "2020-02-07"
}
);
window.hTaxis.criteoBasketTag = [
{event: "setAccount", account: 31165},
{event: "setSiteType", type: window.hTaxis.siteType},
{event: "setHashedEmail", email: ""},
{
event: "viewBasket", item: [
{
id: 1016454,
price: 39.64,
quantity: 1
}
]
},
{
event: "viewSearch",
checkin_date: "2020-01-31",
checkout_date: "2020-02-07"
}
];
</script>
I am trying to pull an array from a different collection using collection2. I have been able to do this with objects using the following example for users:
users: {
type: String,
label: "Inspector",
optional: true,
autoform: {
firstOption: 'Choose an Inspector',
options: function() {
return Meteor.users.find({}, {
sort: {
profile: 1,
firstName: 1
}
}).map(function(c) {
return {
label: c.profile.firstName + " " + c.profile.lastName,
value: c._id
};
});
}
}
},
I would like to do the same but for an array of objects. Here is what the source data looks like:
{
"_id": "xDkso4FXHt63K7evG",
"AboveGroundSections": [{
"sectionName": "one"
}, {
"sectionName": "two"
}],
"AboveGroundItems": [{
"itemSection": "one",
"itemDescription": "dfgsdfg",
"itemCode": "dsfgsdg"
}, {
"itemSection": "two",
"itemDescription": "sdfgsdfg",
"itemCode": "sdfgsdgfsd"
}]
}
Here is what my function looks like:
agSection: {
type: String,
optional: true,
autoform: {
firstOption: 'Select A Section Type',
options: function() {
return TemplateData.find({}, {
sort: {
AboveGroundSections: 1,
sectionName: [0]
}
}).map(function(c) {
return {
label: c.AboveGroundSections.sectionName,
value: c.AboveGroundSections.sectionName
}
});
}
}
},
I know this, it's just not pulling the data for me. I am sure, I am just missing something small. I am trying to pull all objects within the AboveGroundSection array.
Your .map() is iterating over the set of documents but not over the arrays inside each document. Also I don't think your sorting is going to work the way you hope because of the inner nesting.
Try:
agSection: {
type: String,
optional: true,
autoform: {
firstOption: 'Select A Section Type',
options() {
let opt = [];
TemplateData.find().forEach(c => {
c.AboveGroundSections.forEach(s => { opt.push(s.sectionName) });
});
return opt.sort().map(o => { return { label: o, value: o } });
}
}
},
Also if your AboveGroundSections array only has a single key per element then you can simplify:
"AboveGroundSections": [
{ "sectionName": "one" },
{ "sectionName": "two" }
]
To:
"AboveGroundSections": [
"one",
"two"
]