Some users may experience random login-problems to our Community. We are investigating the root cause of this. If you get an error message from CloudFlare, please send the RayID in the message to support@superoffice.com. You may also clear your browser cookies and cashe to solve it. Thanks for your understanding. 

Finding User Defined Fields values on a company card through SearchEngine

lock
push_pin
done
Besvaret
2

In CRMScript I'm trying to find all companies where my UserDefinedField (date) is in a certain timeframe. From what it seems, dates are stored in the UDXXXsmall table as Longs [1], so im thinking i somehow have to do something with the userdef_id (FK udcontactSmall) table of my contact table [2]. However, when trying a few of the "Long" values, i get just long numbers, and not the date values im after.

I've set the UserDefinedField as Indexed, and tried all long01-04, but there are just numbers which i dont understand what to do with.

I can't make sense of how to get the actual values, and would appreciate some help, please let me know if more information is needed 😊

[1] https://docs.superoffice.com/en/custom-objects/reference/index.html

[2] https://docs.superoffice.com/en/database/tables/contact.html

9. jun. 2025 | 04.53 AM

Alle Svar (2)

Hi Frederic, 

I had some UDEF examples in my Person (database name; Contact UI name) 

My example was written in the udpersonSmall table as a value in the long03 column.

The value in this field is stored as a Unix timestamp. Example -> the date 01.08.2024 becomes 1722470400.

If I want to search for a date range. Example, from 30.07.2024 to 10.08.2024 that would would be from 1722297600 to 1723248000. (I used ChatGPT to convert, but there are other alternatives as well.)

So my final code could look something like this:

 

#setLanguageLevel 4;

Void printAllContacts (String udPersonSmall){
    SearchEngine printAllContacts;
    printAllContacts.addField("person.person_id");
    printAllContacts.addField("person.firstname");
    printAllContacts.addCriteria("person.userdef_id", "OperatorEquals", udPersonSmall);
     for (printAllContacts.execute(); !printAllContacts.eof(); printAllContacts.next()) {
     print("ID: " + printAllContacts.getField(0) + " NAME: " + printAllContacts.getField(1) + "\n");
   }
}

Void findAllUdPersonSmallIds (){
    SearchEngine findAllUdPersonSmallIds;
    findAllUdPersonSmallIds.addField("udpersonSmall.udpersonSmall_id");
    findAllUdPersonSmallIds.addCriteria("udpersonSmall.long03", "OperatorGte", "1722297600");
    findAllUdPersonSmallIds.addCriteria("udpersonSmall.long03", "OperatorLt", "1723248000");
    for (findAllUdPersonSmallIds.execute(); !findAllUdPersonSmallIds.eof(); findAllUdPersonSmallIds.next())
        printAllContacts (findAllUdPersonSmallIds.getField(0));
}

findAllUdPersonSmallIds ();

I hope that helps you to move forward with your project.

10. jun. 2025 | 08.53 AM
I thought it looked like Unix Epoch, but when i tried converting it i got dates in 2023 and 2028, where i was looking for something this year :p
Chose to go with the method that Tony put down here, because i can directly just put in the ProgId, but thank you for sharing your insights 😊
12. jun. 2025 | 08.44 AM

We recommend you use the NetServer archive providers to perform search operations. 

In CRMScript, they are the same as described in the archive provider documentation, however in CRMScript all NetServer types have the NS prefix. 

Here is an example to search for all companies where a Date user-defined field value is greater than now.

#setLanguageLevel 4;

// specify the date vaue criteria
DateTime dt;
String dateTime = dt.toString(13,1,true);
String [] values;
values.pushBack(dateTime);

// setup the criteria
NSArchiveRestrictionInfo[] restrictions;
NSArchiveRestrictionInfo res1;
res1.SetName("contactUdef/SuperOffice:3"); // user defined field progid == SuperOffice:3
res1.SetOperator("afterTime");
res1.SetValues(values);
restrictions.pushBack(res1);

// populate if a sort order is desired
NSArchiveOrderByInfo[] order;
 
// defined the desired entity (provider specific)
String[] desiredEntities = String("contact").split(",");

// select desired columns. All available listed here: https://docs.superoffice.com/en/api/netserver/archive-providers/reference/simplecontact.html
String[] desiredColumns = String("contactId,name,contactUdef/SuperOffice:3").split(",");

// use paging for large datasets
Integer pageSize = 10;

// execute the query
NSArchiveAgent archiveAgent;
NSArchiveListItem[] rows = archiveAgent.GetArchiveListByColumns("SimpleContact", desiredColumns, order, restrictions, desiredEntities, 0, pageSize);

foreach (NSArchiveListItem row in rows) {
  Map rowData = row.GetColumnData();
  String contact_contactId = rowData.get("contactId");
  String contact_name = rowData.get("name");
  String contact_dateUdef = rowData.get("contactUdef/SuperOffice:3");
  
  printLine(contact_contactId + ": " + contact_name + " => " + contact_dateUdef );
}

Hope this helps!

11. jun. 2025 | 09.58 AM
This was definetly an easier way to do this, thank you for sharing 😊
12. jun. 2025 | 08.41 AM

Tilføj svar