-
Notifications
You must be signed in to change notification settings - Fork 53
How to Change a Page Title in a Database #360
Unanswered
guixingzhe
asked this question in
Q&A
-
I have created a repeat template, which title is @ Today xxx, in a datebase. The method UpdateProperty is used for change Title. But something wrong after run the method, that is body.properties.Title.title[0].mention.date.start should be defined. So I try to adding a RichTextMention property to solve it , and the proplem occurs
internal class DailyTrackerPage
{
public string Title { get; set; }
public bool? Done { get; set; }
public DateTime CreatedTime { get; set; }
public RichTextMention Mention { get; set; }
public DailyTrackerPage(Page page)
{
CreatedTime = page.CreatedTime;
Done = page.Properties[nameof(Done)] is FormulaPropertyValue formula ? formula.Formula.Boolean : default;
TitlePropertyValue? title1 = page.Properties[nameof(Title)] as TitlePropertyValue;
Mention = title1.Title.FirstOrDefault() is RichTextMention mention ? mention : default;
DateTime dateTime = Convert.ToDateTime(Mention.PlainText);
Mention.Mention.Date = new DatePropertyValue { Date = new Date { Start = dateTime } };
Title = page.Properties[nameof(Title)] is TitlePropertyValue title
? string.Join(null, title.Title.Select(x => x.PlainText))
: string.Empty;
}
}
private static async Task UpdateProperty(Page? page)
{
if (page != null)
{
DailyTrackerPage trackerPage = new(page);
var newTitle = new List<RichTextBase> { { trackerPage.Mention }, { new RichTextBase { PlainText = "Voc30" } } };
if (trackerPage.Title.Contains("Voc"))
{
await Console.Out.WriteLineAsync($"Title{trackerPage.Title} ID:{page.Id}").ConfigureAwait(false);
await MyClient.Client.Pages.UpdatePropertiesAsync(page.Id, new Dictionary<string, PropertyValue>
{
{ "Title", new TitlePropertyValue() { Title = newTitle } }
}).ConfigureAwait(false);
}
}
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment