Skip to content

The AddDataRowsToSiteTemplate fields requested should also be validated if can be retrieved #5020

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions src/Commands/Provisioning/Site/AddDataRowsToSiteTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,43 +160,42 @@ protected override void ExecuteCmdlet()
}
}
}

List<Microsoft.SharePoint.Client.Field> fieldsToExport;
// Get the fieds to export
if (Fields != null)
{
fieldsToExport = [];
foreach (var fieldName in Fields)
{
Microsoft.SharePoint.Client.Field dataField = fieldCollection.FirstOrDefault(f => f.InternalName == fieldName);

// Discard all fields unsupported
Microsoft.SharePoint.Client.Field dataField = fieldCollection.FirstOrDefault(f => f.InternalName == fieldName && !_unsupportedFieldTypes.Contains(f.FieldTypeKind));
if (dataField != null)
{
var defaultFieldValue = GetFieldValueAsText(ClientContext.Web, listItem, dataField);
if (TokenizeUrls.IsPresent)
{
defaultFieldValue = Tokenize(defaultFieldValue, ClientContext.Web, ClientContext.Site);
}

row.Values.Add(fieldName, defaultFieldValue);
fieldsToExport.Add(dataField);
}
}
}
else
{
// All fields are added except readonly fields and unsupported field type
var fieldsToExport = fieldCollection.AsEnumerable()
.Where(f => !f.ReadOnlyField && !_unsupportedFieldTypes.Contains(f.FieldTypeKind));
foreach (var field in fieldsToExport)
// Discard all fields readonly and unsupported field type
fieldsToExport = [.. fieldCollection.AsEnumerable().Where(f => !f.ReadOnlyField && !_unsupportedFieldTypes.Contains(f.FieldTypeKind))];
}

// Get validate field and get data
foreach (Microsoft.SharePoint.Client.Field field in fieldsToExport)
{
if (listItem.FieldExistsAndUsed(field.InternalName))
{
var fldKey = (from f in listItem.FieldValues.Keys where f == field.InternalName select f).FirstOrDefault();
if (!string.IsNullOrEmpty(fldKey))
var fieldValue = GetFieldValueAsText(ClientContext.Web, listItem, field);
if (TokenizeUrls.IsPresent)
{
var fieldValue = GetFieldValueAsText(ClientContext.Web, listItem, field);
if (TokenizeUrls.IsPresent)
{
fieldValue = Tokenize(fieldValue, ClientContext.Web, ClientContext.Site);
}
row.Values.Add(field.InternalName, fieldValue);
fieldValue = Tokenize(fieldValue, ClientContext.Web, ClientContext.Site);
}
row.Values.Add(field.InternalName, fieldValue);
}
}

rows.Add(row);
}
}
Expand Down