-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathSetTaxFieldValue.php
25 lines (20 loc) · 1.01 KB
/
SetTaxFieldValue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
require_once '../../vendor/autoload.php';
$settings = include('./../../../tests/Settings.php');
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\Taxonomy\TaxonomyFieldValue;
use Office365\SharePoint\Taxonomy\TaxonomyFieldValueCollection;
$credentials = new ClientCredential($settings['ClientId'], $settings['ClientSecret']);
$siteUrl = $settings['TeamSiteUrl'];
$ctx = (new ClientContext($siteUrl))->withCredentials($credentials);
$tasksList = $ctx->getWeb()->getLists()->getByTitle("Tasks");
$taxFieldValue = new TaxonomyFieldValue("Sweden", "f9a6dae9-633c-474b-b35e-b235cf2b9e73");
$taxFieldValueAlt = new TaxonomyFieldValue("Germany", "04872f90-9990-4fe4-8cff-32cc8ca05417");
$taskProps = array(
'Title' => "New task N#" . rand(1, 100000),
"Country" => $taxFieldValue,
"Countries" => new TaxonomyFieldValueCollection(array($taxFieldValue, $taxFieldValueAlt))
);
$item = $tasksList->addItem($taskProps)->executeQuery();
print("List item created.");