For each client we have, we associate their name with an ID number in a database. However, we sign people in by name. I am trying to convert the names into their ID number in a spreadsheet.
I have a list of all the names and corresponding IDs. I realize that I could hard code it so that it would look something like:
for (i=0; i < 31; i++) {
if name = 'john doe'
id = 256589
elseif name = 'jane doe'
id = 248352...}
and repeat that for each client. I've tested with a couple names and this solution does work. Since we don't have that many individuals come in it wouldn't be impossible to just repeat it. However, I would like to know if there are any shortcuts available.
It depends where you're doing this lookup.
This looks like script so you could use an object with the names as keys:
function getIdFromName(name) {
// list of all employees and ids
let employees = {
"john doe": 256589,
"jane doe": 248352
}
if (employees[name]) {
return employees[name]
} else {
// this covers the case if name not found
return false
}
}
// in rest of your code
var id = getIdFromName(name)
If you want to do the lookup in the sheet, you can use a lookup table containing names and ids then use VLOOKUP/INDEX(MATCH()) to find the corresponding ID
Related
I currently have two lists, one is from an external api (splynx), which returns a list of all customers, and another list which returns a list of all Account names from the contacts module in Zoho crm, at the moment, I just want write a code that confirms if the two lists contain matching entries (like one entry in the splynx list matches another entry in the crm list).
What I actually want to achieve is for each matching entry, I want to update crm records with the Customer ID field from Splynx, with a custom field called Splynx ID in the accounts module in CRM (because this ID is auto generated so as to maintain consistency across both apps). I want to know if this even achievable.
This is the code I have written so far
headersmap = Map();
headersmap.put("Authorization","Basic xxxxxxx);
response = invokeurl
[
url :"https://selfcare.dotmac.ng/api/2.0/admin/customers/customer?"
type :GET
headers:headersmap
];
AccountlistSplynx = List();
li1 = List();
li2 = List();
li3 = List();
rows = response.toJSONList();
rows1 = response.toJSONList();
rows2 = response.toJSONList();
for each row in rows
{
Name = row.getjson("name");
AccountlistSplynx.add(Name);
}
for each row in rows1
{
Address = row.getjson("street_1");
li1.add(Address);
}
for each row in rows2
{
CustomerID = row.getjson("id");
li2.add(CustomerID);
}
Accountlistzoho = List();
mp = Map();
contacts = zoho.crm.getRecords("Contacts");
for each contact in contacts
{
account = ifnull(contact.getJSON("Account_Name"),Map());
if(account.size() > 0)
{
accountname = account.getJSON("name");
Accountlistzoho.add(accountname);
}
}
if ( Accountlistzoho == AccountlistSplynx )
{
info "Matching records!";
}
else
{
info "No matching records!";
}
I also want to know if this is the best route to follow in trying to achieve this because I had already imported these contacts from Splynx to CRM before I realized that I did not create the custom field for Accounts
Take a look at the intersect list function:
<variable> = <listVariableOne>.intersect( <listVariableTwo> );
Note!:
<listVariableOne>.intersect( <listVariableTwo> );
and
<listVariableTwo>.intersect( <listVariableOne> );
should return the same intersection set but sometimes one of these calls returns a smaller set. To work around this, call intersect() both ways and if they differ use the one that gives the expected set.
For this task intersect() would be used something like this:
headersmap = Map();
headersmap.put("Authorization","Basic xxxxxxx);
response = invokeurl
[
url:"https://selfcare.dotmac.ng/api/2.0/admin/customers/customer?"
type :GET
headers:headersmap
];
// Note: Using a Map to associate Splynx names and ids.
SplynxMap = Map();
rows = response.toJSONList();
for each row in rows
{
SplynxMap.put(row.getjson("name"), row.getjson("id");
}
// Here make a list of Splynx names based on the map keys.
AccountlistSplynx = List();
AccountlistSplynx = SplynxMap.keys();
// Intersect() function
ItemsToProcess = Accountlistzoho.intersect(AccountlistSplynx);
// Get Zoho record and update with Splynx Customer ID
// Here is one way to do this, but probably not the best or
// most efficient. There is should be a way in CRM to request
// a specific record based on the "name" field and avoid
// looping through contacts for each item to process.
for each item in itemsToProcess
{
for each contact in contacts
{
account = ifnull(contact.getJSON("Account_Name"),Map());
if(account.size() > 0)
{
if ( item == account.getJSON("name"))
{
account.Splynx_ID = SplynxMap.get(item);
}
}
}
}
Regarding your needs, do you want to update Zoho CRM records if they are matched in Splynx records?
Step 1:
Store all Splynx records into the List data type variable in the deluge.
Store all Zoho records into the List data type variable in the deluge.
Step 2:
Assume that API field Names of both Lists are not equally matched.
Step 3:
This is how to determine matched records in Zoho records if we assume that Account Name is the criteria to be said it is matched. Please note that api_field_name or keys will be different from your actual data.
SplynxData = {{"s_account_name":"Account A","ID":"s_ID_1"},{"s_account_name":"Account B","ID":"s_ID_2"},{"s_account_name":"Account C","ID":"s_ID_3"},{"s_account_name":"Account D","ID":"s_ID_4"}};
ZohoData = {{"z_account_name":"Account A","ID":"z_ID_1"},{"z_account_name":"Account B"},{"z_account_name":"Account C"}};
ZohoData_group_Name = Map();
for each ZohoData_item in ZohoData{
item_map = Map();
ZohoData_group_Name.put(ZohoData_item.get('z_account_name'),ZohoData_item);
}
for each SplynxData_item in SplynxData{
matched_zoho_item = ZohoData_group_Name.get(SplynxData_item.get('s_account_name')) ;
if (matched_zoho_item != null){
info matched_zoho_item;
//Do zoho.crm.updateRecords methods
}
}
You can try this deluge script in https://deluge.zoho.com/tryout.
Please refer to this link on how to update Zoho Records https://www.zoho.com/deluge/help/crm/update-record.html
I'm working with PHP, I have a json structure which looks like that :
{
"events": [
{
"timestamp": 1468774519,
"id": 75964,
},
{
"timestamp": 1468771410,
"id": 24891,
},
// etc
I need to fetch 5 events in a row, but starting from one specific id, so my first idea is to loop every event from the beginning and check if the id is the offset i'm looking for, and then when i get it i can loop the next 5 events.
But is there a better way to do so ? It could possibly loop through hundreds of events so maybe there's a better way to get there ? thanks
Since the ids aren't in numeric order, you can't use a binary search, so you need to use a sequential search. Here's an example in JavaScript. Also note this code assumes the id is present and there are at least four more events after it in the array.
var index = 0;
var id = 12345; // for example
var json = {...}; // whatever that object was
while(json.events[index].id!=id) {
index++;
}
// found the one, do something with the next five
for(var i=0; i<5; i++) {
var event = json.events[index+i];
// do something
}
In my opinion, you can only take one loop over the events with a filter event.id >= theId,and then check if the filtered array contains theId. if you get it, you can sort this smaller array and take the 5 events.
First I would make a key:value hash object (a lookup object), where the key would be the id from your structure, and the value would be the reference to the event. As a result, you iterate over the structure only once and then get all the events from the lookup structure, by just accessing them by their keys.
You could sort it as well(ideally, you could get it already sorted by id from your source of data) and then use a binary search algorithm.
Im trying to work out how to append a zero to a specific JSON decoded array value for multiple records stored in a MySQL table according to some conditions.
for example, for table 'menu', column 'params'(text) have records containing JSON decoded arrays of this format:
{"categories":["190"],"singleCatOrdering":"","menu-anchor_title":""}
and column 'id' has a numeric value of 90.
my goal is to add a zero to 'categories' value in menu.params whenever (for example) menu.id is under 100.
for this records the result being
{"categories":["1900"],"singleCatOrdering":"","menu-anchor_title":""}
so im looking for a SQL Query that will search and find the occurrences of "categories": ["999"] in the Database and update the record by adding a zero to the end of the value.
this answer is partially helpful by offering to use mysql-udf-regexp but its referring to REPLACE a value and not UPDATE it.
perhaps the REGEXP_REPLACE? function will do the trick. i have never used this library and am not familiar with it, perhaps there is an easier way to achieve what i need ?
Thanks
If I understand your question correctly, you want code that does something like this:
var data = {
"menu": {
"id": 90,
"params": {
"categories": ["190"],
"singleCatOrdering": "",
"menu-anchor_title": ""
}
}
};
var keys = Object.keys(data);
var columns;
for (var ii = 0, key; key = keys[ii]; ii++) {
value = data[key];
if (value.id < 100) {
value.params.categories[0] += "0";
alert(value.params.categories[0]);
}
}
jsFiddle
However, I am not using a regular expression at all. Perhaps if you reword the question, the necessity of a regex will become clearer.
This should be a fairly simple one.
myobject has various properties, _id, name, createdBy, date etc
In my find query I want to only return specific fields from within myObject. So for example, what would I need to do to modify the find query below so that only name was returned?
myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch();
Currently this will return everything in myObject which it should do, I just want one field within myObject returned.
Here is a way to do it within the query:
myCollection.find({createdBy: someId}, {fields: {'myObject.name':
1}}).fetch();
Note the quotes around
'myObject.name'
Lets assume we are talking about posts, and a post document looks like this:
{
_id: 'abc123',
title: 'All about meteor',
author: {
firstName: 'David',
lastName: 'Weldon'
}
}
You can then extract all of the last names from all of the authors with this:
var lastNames = Posts.find().map(function(post) {
return post.author.lastName;
});
Modify the selector and options as needed for your collection. Using fields in this case may be a small optimization if you are running this on the server and fetching the data directly from the DB.
I have collection of numbers like: 11111, 12345, 12346 stored in a list in c# code. I need to compare this list against sql database column of numbers similar to this and find out if matching numbers exist. Below is what i am doing:
foreach (number in numbers)
{
//get column data through sql reader and iterate through it:
foreach(column in columnData)
{
if(number == column)
{
// do something
}
}
my question is this right approach? Or is there a better way to do this? As it looks like this requires lots of processing.
I would so something like this..
var matches = columnData.Where(z=> numbers.Contains(z=>z.columnData)).ToList();
or
var matches = columnData.Select(z=> z.columnData).Intersect(numbers);