Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i get the field of library #333

Closed
alfredoquintana opened this issue Jul 28, 2023 · 1 comment
Closed

how can i get the field of library #333

alfredoquintana opened this issue Jul 28, 2023 · 1 comment
Labels

Comments

@alfredoquintana
Copy link

hi, I need to retrieve the fields of a library, and I have this code.

        1 $libraryName = trim($libraryName); // Eliminar espacios en blanco adicionales
        2 $fields = $this->credentials->getWeb()->getLists()->getByTitle($libraryName)->getFields();
        3 $field = $fields->filter("InternalName eq '$nameField'")->top(1)->get()->executeQuery();
        4 if ($field->getCount() == 0) {
            $fieldProperties = new FieldCreationInformation();
            $fieldProperties->Title = $nameField;
            $fieldProperties->FieldTypeKind = FieldType::Text;
           }
        5   $field = $fields->add($fieldProperties);
        6     $credentials->executeQuery();

but when the library is "Documentos compartidos" (Shared Documents), the code its not found.

However, when the library is named "Documentos compartidos" (Shared Documents), the code doesn't work. When I use var_dump on lines 2, 3, and 4, I get nothing. The issue only occurs when $libraryName is set to "Documentos Compartidos" (Shared Documents).
Goodbye for now, I hope you can help me

@vgrem vgrem added the question label Oct 1, 2023
@alfredoquintana
Copy link
Author

Well, as a result, I did it this way. in case it is useful to anyone

   try {
        $field = $credentials->getWeb()->getLists()
            ->getByTitle($libraryName)->getFields()
            ->getByInternalNameOrTitle($fieldName);
        $credentials->load($field);
        $credentials->executeQuery();
        $columnTitle = $field->getTitle(); 
        return $columnTitle;
    } catch (\Exception $e) {
        $fieldProperties = new FieldCreationInformation();
        $fieldProperties->Title = $fieldName;
        $fieldProperties->FieldTypeKind = FieldType::Text;
        $field = $credentials->getWeb()->getLists()->getByTitle($libraryName)
            ->getFields()->add($fieldProperties);
        $credentials->executeQuery();
        return true;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants