This topic contains 4 replies, has 0 voices, and was last updated by chanarbon 7 years, 2 months ago.

  • Author
    Posts
  • #6472 Score: 0

    adurangalvis
    • Contributions: 0
    • Level 1

    Hello,

    we are calling a saved search by its internal ID, and we want to output some of the custom fields from the search but we have had no luck. This is what we have so far, the out of the box IDs such as email, last name, birthday and subsidiary work. The custom field one does not work, I have tried putting the field id inside intelnalid() but it doesn’t like that.

    Code:
    EmployeeSearchAdvanced employeeSearch = new EmployeeSearchAdvanced();
    //set saved search id
    employeeSearch.savedSearchId = “929”;
    // perform the search
    SearchResult result = nsservice.search(employeeSearch);
    if (result.totalRecords > 0)
    {
    Console.WriteLine(result.totalRecords);

    SearchRow[] searchRows = result.searchRowList;

    if (searchRows != null && searchRows.Length >= 1)
    {
    for (int i = 0; i < searchRows.Length - 1; i++) { EmployeeSearchRow employeeRow = (EmployeeSearchRow)searchRows[i]; string email = employeeRow.basic.email[0].searchValue; string lastName = employeeRow.basic.lastName[0].searchValue; var birthDate = employeeRow.basic.birthDate[0].searchValue; var subsidiary = employeeRow.basic.subsidiary[0].searchValue.internalId; string display = employeeRow.basic.customFieldList[0].ToString(); string adDisplayName = employeeRow.basic.customFieldList[0].internalId(); Console.WriteLine(lastName + "|"); Console.WriteLine(email + "|"); //Console.WriteLine(birthDate + "|"); Console.WriteLine(display + "|"); } }
    This is a cached copy. Click here to see the original post.

  • #6473 Score: 0

    adurangalvis
    • Contributions: 0
    • Level 1

    **bump**

  • #6474 Score: 0

    latchadev
    • Contributions: 0
    • Level 1
  • #6475 Score: 0

    jc122500
    • Contributions: 0
    • Level 1

    It might be too late and not a perfect way by far, but its how I was able to get it to work. Hopefully it will give you a starting point to figure it out. I created a dictionary outside the search and then loop through the custom fields inside. An example using your code would be something like this. You can use the internal id of the field once it loops through. I am handling the search a little differently so not sure if the [0] is needed on customfieldlist.

    –outside loop

    Dictionary CustomFields = new Dictionary();

    –inside loop

    CustomFields.Clear();

    foreach(CustomFieldRef c in employeeRow.basic.customFieldList[0]){

    if (c.GetType() == typeof(DateCustomFieldRef)) {

    CustomFields.Add(c.internalId,((DateCustomFieldRef )c).value.ToString());

    }

    else if (c.GetType() == typeof(SelectCustomFieldRef))

    {

    CustomFields.Add(c.internalId, ((SelectCustomFieldRef)c).value.ToString());

    }

    else if (c.GetType() == typeof(StringCustomFieldRef))

    {

    CustomFields.Add(c.internalId, ((StringCustomFieldRef)c).value.ToString());

    }

    else if (c.GetType() == typeof(BooleanCustomFieldRef))

    {

    CustomFields.Add(c.internalId, ((BooleanCustomFieldRef)c).value.ToString());

    }

    }

    if (CustomFields.ContainsKey(“185”))

    {

    empcustomone = CustomFields[“185”];

    }

    if (CustomFields.ContainsKey(“147”))

    {

    empcustomtwo = CustomFields[“147”];

    }

  • #6476 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    For this concern,

    1. If the value for the custom field is not empty, what you do get from customFieldList[0].searchValue (for non-select fields) and customFieldList[0].searchValue.internalId for the select fields.

    2. Have you tried it on other fields.

    From my point of view, this should be work.

You must be logged in to reply to this topic.