Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to Change a Page Title in a Database #360

Unanswered
guixingzhe asked this question in Q&A
Discussion options

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);
 }
 }
 }
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /